Up to Main Index Up to Journal for August, 2023
JOURNAL FOR TUESDAY 1ST AUGUST, 2023
______________________________________________________________________________
SUBJECT: Not quite closures…
DATE: Tue 1 Aug 19:30:11 BST 2023
I was just writing away, updating Mere ICE documentation for functions, when
an idea hit me. Writing about stuff you’ve implemented is good for generating
ideas. One monumentally quick‘n’dirty hack later I had the following working:
>cat delayed.mr
d = call getDelayed 3 5
println call d // prints 15
exit
getDelayed: func a b
return [](delayed a b)
delayed: func x y
return x*y
endfunc
endfunc
>mere delayed.mr
15
>
It’s not quite a closure really, it does not capture all of the surrounding
environment. However, it’s damn close. For now the idea is parked as “delayed
functions”. I like the idea as it fits Merer’s style quite well…
To get this into Mere proper I’d have to add a new type and all the associated
tests. In the above ‘[]( … )’ creates an array of any type. This is similar to
‘[]int(1 2)’ or ‘[]string("a" "b")’ but without specifying the array type.
An array of any type is a type I have planned, but not just yet. I want to get
Mere ICE updated with functions before anything else.
For now, as I said, parked. But I thought it interesting enough to mention it.
This will also act as a reminder to myself ;)
--
Diddymus
Up to Main Index Up to Journal for August, 2023