How do you ringify a block with JavaScript?

With lambda! :~)

huh??

The gray ring is Snap!'s visual representation of what in text languages is called lambda (the Greek letter λ, which is what Church called it in the lambda calculus). In text languages you also have to use named inputs (formal parameters) instead of Snap!'s empty-slot replacement. So instead of
untitled script pic
you say (lambda (num) (+ num 1)) if you're in a Lisp. In JavaScript it's

(function (num) {return num+1})

or in recent versions abbreviated as

((num) => num+1)

I meant if you have a Command/ReporterBlockMorph that's not in a ring as a value (don't ask) how would you put the block in a ring using Snap! native JavaScript?

From my research (just outputting blocks to the dev console and looking at their properties and functions) when making my "script builder" library, you do this:

new Context(null, block);

I forgot what the first parameter is for but it's useless. I think it's the parent context?
I'm not sure if this applies to ringifying a ring though... (probably doesn't, you need a RingMorph)

I don't think this is a meaningful question. The ring is the visual representation of code as data. If you have a BlockMorph as a user-visible value, it will be shown with a ring.

I want to have a filter in the forums. Whenever the word "JavaScript" appears in a post that post can't be and "advanced" topic, but instead is moved to "dumb questions" :slight_smile:

Aw, don't be mean.

Do not move my JavaScript tutorial to "dumb questions".

Don't worry, I was joking, (albeit only half). Your JS tutorial is great, I love it!

I have stumbled on "Lambda for dummies" at The Lambda Calculus for Absolute Dummies (like myself) - Joscha Bach which I find more accessible than the Wikipedia article. If you like it, you may want to add the link to the Faq post about the lambda, too.

Wikipedia is just there to explain what it is, and more information about it, not how to use it, that's what other sites are for.

It's okay apart from the typos in the equations... Took me a while to figure out that I wasn't failing to understand something. :~)

Can you, please, make a screenshot of the typos and tell us what it should be written, instead, to be correct?


This isn't exactly a typo, just doesn't say what he means; "The bound variable s will be replaced by nothing" should really say "the value that replaces the bound variable s isn't actually used for anything, because it does not occur in the body." But it sounds as if the s stays s or becomes an empty string, neither of which is true. It's like saying
untitled script pic untitled script pic (1)
The s is replaced by a, but the a is then unused in the computation.

... but the other thing I thought was a typo really isn't; I misread it. oops.

So yeah it's okay. Did all the text make you more comfortable reading the formal notation, or did you just skip the formal notation because the text was enough for you?

I tried to "translate" (in my head) the textual notation to what (I imagined) it would look like in Snap!

P.S.
... the empty input slot, that is subsequently filled by the what ever input the function is then called with. Right?

Thank you for clarifying what he meant to say, but didn't.

Yeah. If you want it to look more like official lambda calculus notation you can give the ring a formal parameter:


and then when you call it with (ab) as input...

and after substitution it's

It's kinda too bad that our notation for calling a function is less elegant than the text version. I'm working on a project that has
new-church-soln script pic and new-church-soln script pic
so that example would be


... but I need Jens to implement a slight change to how upvars work, to make it possible. Then I can make an activity in which you implement arithmetic and all that, in exactly lambda calculus notation. Jens was resistant but I think we have agreed on a way to do it that's just enough of a change to make my project work without breaking things like
untitled script pic    untitled script pic
(The issue is that I want to limit the scope of an upvar to the expression containing it, but this SET block needs the scope of the upvar to continue after the SET call. The current definition of upvars breaks recursive lambdas, so this

which should compute the factorial of 3 currently returns 4 instead of 6.)

I see.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.