Sujet : Re: on racket and other Lisps
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.lispDate : 01. Jun 2024, 06:24:15
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3e7pf$2kc2t$4@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : Pan/0.158 (Avdiivka; )
On Fri, 31 May 2024 23:48:37 -0300, Julieta Shem wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
Perhaps look at Python as the closest we have managed to come to “Lisp
2”. It still allows for homoiconicity to some degree.
Can you give an example of Python's homoiconicity?
Sure. Have a look at this library <
https://gitlab.com/ldo/seaskirt/>. It’s
a set of wrappers around the various management APIs available for the
Asterisk telephony engine.
I wanted to create both synchronous and asynchronous versions of each of
the wrapper classes. For example,
def func(...) :
...
res = net_call(...)
...
#end func
versus
async def func(...) :
...
res = await net_call_async(...)
...
#end func
but I didn’t want to write out the “...” parts (which made up about 90% of
the code) twice. So what I actually wrote looked like this:
async def func(...) :
...
if ASYNC :
res = await net_call(...)
else :
res = net_call(...)
#end if
...
#end func
That “ASYNC” is not defined anywhere: it’s just a placeholder. But after
the code is compiled to AST form, I run a preprocessor which looks for
those conditionals, and expands the alternatives inline, generating two
versions of the code which correspond, in source form, to the two versions
I avoided writing explicitly.
One fun thing is, I also figured out I could do class instantiations
asynchronously.
So even though the macro preprocessing system adds about 160 lines to the
module, I estimated the whole thing is still over 500 lines smaller than
it would be if I had written out all the code by hand. That’s 500 less
lines for bugs to occur in, and for me to maintain.