So if I want to write these bits in something other than PowerShell-the-language but want to take advantage of PowerShell-the-CLI what would it look like? Can you rewrite this same script in some other language (say Python or OCaml or Racket or…)?
So if I want to write these bits in something other than PowerShell-the-language but want to take advantage of PowerShell-the-CLI what would it look like? Can you rewrite this same script in some other language (say Python or OCaml or Racket or…)?
Adding a bit more context and a tool you might like: PowerShell is meant to be as easy as possible. I recently built a #Turtle #Graphics engine in #PowerShell i.e. turtle SierpinskiTriangle 42 4 # makes a fractal. I can | Select Width, Height or | Select -Expand SVG psturtle.com
This may be younger than #Python #Turtle #Graphics, but it can already do many things that Python will not do out of the box. The syntax will almost always be shorter (and care less about spacing) Why? Because PowerShell is a highly extensible language with very flexible syntax.
I've got my own opinions about these kinds of topics as pedagogical devices, so maybe best not to get me started on this topic. (-:
Happy to hear them, especially since I basically built this variation of Turtle to teach, inspire, and peel back layers of the universe. ( Also, in case this isn't clear, if you work on a language you end up a language nerd ) Please share your opinions, I'm eager to hear them.
parentheticallyspeaking.org/articles/how...
Btw, if you want a real recursive head trip, do you know of any other language that allows anonymous recursion? It's one of the more fun little lambdas to bust out in #PowerShell. I still haven't seen that feature anywhere else, but my knowledge is finite. 😉. You seen it anywhere ?
I'm not sure what "anonymous recursion" means really, but the Y-combinator might be what you're looking for, and it's encodable in numerous languages directly or with a little bit of effort (depending on eager vs lazy evaluation, the specific type structure of the language, etc.).
Hmm. I suppose one way to think of it would be in terms of a "automatic" y-combinator. & $myinvocation.MyCommand.ScriptBlock # brief anonymous recursion example. Let's me build a recursive lambda without ever saving it to a variable. ( $myInvocation is an automatic variable )
Is this the sort of thing you mean? Note that there is no recursive name reference. I've also purposely created an outer function so we can confirm the two instances (non-rec-lucas and non-rec-fib) are not confused with each other, i.e., they really are from this *invocation*.
Looks like it. What language is that? (looks vaguely functional, but I don't think it's scheme)
Good article. Recursion is a tricky topic to teach and explain. FWIW, the Turtle I linked to doesn't use it ( yet ), as the object pipeline helps avoid it. If I were looking for a practical example to teach, I would probably try for serialization ( for example, converting objects to css ).
For the sake of demonstration, let's just say I have a Racket or Python script that gives me back a series of numbers, one per line If we pipe that script to foreach-object, we can just cast to a [double] python ./some.py | % { ($_ -as [double])/2 }
It would vary by the language. Almost every other language does not allow for seamless multi-value return, and most of them lack an object pipeline. In general, you'd use loops, but then you'd have to look at all objects at once, instead of as a pipeline of objects.