A little puzzle (a better one this time, I promise, but still pretty easy): Find a sequence of characters to write in place of <X>
so that (begin ( <X> )
<do stuff> ...+)
is equivalent to (begin
<do stuff> ...+)
but also so that (let ( <X> )
<do stuff> ...+)
is equivalent to (let ()
<do stuff> ...+)
Reply in thread to avoid spoilers. (edited as per @sorawee’s comments below)
@laurent.orseau I’m confused. Your main question is, how to convert
(let ()
<do stuff> ...+)
to
(begin ( <X> )
<do stuff> ...+)
right?
I don’t understand anything at all in:
so that this is equivalent to
(begin
<do stuff> ...+)
and also this
(let ( <X> )
<do stuff> ...+)
is equivalent to
(let ()
<do stuff> ...+)
SInce
(let ()
<do stuff> ...+)
and
(begin
<do stuff> ...+)
are not equivalent.
(edited, yes it was ambiguous)
Still confused :disappointed:
Your main code is:
(let ()
<do stuff> ...+)
But then, you ask: you want
(begin ( <X> )
<do stuff> ...+)
so that this is equivalent to
(begin
<do stuff> ...+)
Why suddenly talking about two begin
s? What happens to the main code?
Your task is to find a sequence of characters to put in place of <X>
so that (begin ( <X> ) body ...+)
is equivalent to (begin body ...+)
and also so that (let ( <X> ) body ...+)
is equivalent to (let () body ...+)
oh, ok, so I should disregard
(let ()
<do stuff> ...+)
right?
Because that’s where I came from. I had the original code, and I wondered how to replace let
with begin
while not commenting out ()
Yes, I’ll edit
better?
yep!
Thanks for helping to clarify!
Not sure if this is an intended solution:
(let ([values values])
1)
;==
(let ()
1)
;-----------------------------
(begin ([values values])
1)
;==
(begin
1)
It is indeed, well done :slightly_smiling_face:
and now you can see on Discourse why this puzzle came up :slightly_smiling_face:
ah
application of any named unary function to itself?
@capfredf Like ([+ +])
? :wink:
“which will not raise a type error”
:stuck_out_tongue:
Like ([displayln displayln])
? :stuck_out_tongue: (though ok, you did say ‘function’)
It also doesn’t work with parameters either: ([current-label current-label])
is ok with let, but with begin (current-label)
returns the procedure current-label
instead of whatever label it was containing before
Ah, I forgot there was an extra pair of parens
then any f : (-> Any (-> Any))
I get gtk warnings when running slideshow programs on gnome 42. I don’t think they are slideshow issues per se. Which repository should I post an issue to? racket/gui?
(I didn’t get them yesterday when I was on gnome 41)
That might be correct, surprisingly. I thought only identity functions would work (I need to give it some more thought)
There is a further complication. Consider:
(begin ([const const])
1)
This works everywhere except at the module / top-level context, where the application is spliced out, resulting in
#<procedure:const>
1
@laurent.orseau it must be variadic identity, too. Otherwise, you will have arity error and/or incorrect results.
Perhaps
f : (-> Any (-> (values)))
?
racket/gui
sounds right