blog/2025-07-31/the-loop-and-more-loops/ #256
Replies: 3 comments
-
Hey ingy, I'm very fresh to Yamlscript and clojure.. I have tried for a few hours to write a simple yamlscript isPrime function, and am having no luck (similarly, none of the AI chat bots are having any luck either!). How would you do it? I am coming from more of a Javascript / Typescript / Go background. Trying to assign / reassign variables outside of loops, etc? The whole thing has got me pretty messed up :/ I looked over some of the rosetta stuff too, but still am just missing something |
Beta Was this translation helpful? Give feedback.
-
Hi @pwdrysdale ! Apologies for not seeing this sooner! Here's a quick example of defining and calling a !YS-v0
defn main(*nums):
each num nums: !:say
if prime?(num): +
"$num is prime"
"$num is not prime"
defn prime?(n):
(n > 1) &&
\(zero?(n % _))
.not-any?(range(2 n)) and run it:
There's a lot to discuss here. How about instead of me trying to tell you the finer points here, let's turn this into a dialog. Looking forward to your replies... |
Beta Was this translation helpful? Give feedback.
-
WRT to functional (FP) versus imperative programming, it's a bit of a mind switch but not a huge one. Say you have a variable called
You never changed a mapping here. You just created a new one and then re-bound Another thing to keep in mind is that you can't return early from a function. Hope this sparks more questions. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
blog/2025-07-31/the-loop-and-more-loops/
Program in YAML — Code is Data
https://yamlscript.org/blog/2025-07-31/the-loop-and-more-loops/
Beta Was this translation helpful? Give feedback.
All reactions