[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Happy birthday, Guile!

From: Linus Björnstam
Subject: Re: Happy birthday, Guile!
Date: Sun, 16 Feb 2020 17:20:48 +0100
User-agent: Cyrus-JMAP/3.1.7-802-g7a41c81-fmstable-20200203v1

Hooray! I have a bunch of small utils that I use to make repl life easier. One 
thing I did to scratch an itch is a clojuresque lambda shorthand (cut on 
steroids) for guile. It transverses whatever expressions you put into it and 
rewrites it into a lambda where all identifiers of the form %n where n is an 
integer gets transformed into a lambda argument.

 (megacut (let ((a "Hello ")) (string-append a %1)))
    => (lambda (%1) (let ((a "Hello")) (string-append a %1)))

Using read-hash-extend one can write #%:

#%(apply + (/ 10 %1) %&)
   => (lambda (%1 . %&) (apply + (/ 10 %1) %&))

It supports arbitrary many arguments, and also allows for "ignoring" arguments: 

#%(display %3)
    => (lambda (%1 %2 %3) (display %3))

A regular % is also a shorthand for %1:

 #%(+ % %) =>  (lambda (%1) (+ %1 %1))

I use it daily. 20 minutes of scripting that the last year or so probably saves 
me at least 25 seconds of typing :)

It has rudimentary unhygienic support for nesting, which may or may not be a 
terrible idea.

I have another useful little function, port->list which takes a port and a read 
function and returns a list of whatever the reader function returns until the 
port EOFs. less powerful than port-fold, but less fuss to use when you just 
want a list. I leave that as an exercise for the reader, though.

  Linus Björnstam

On Sun, 16 Feb 2020, at 15:56, Ludovic Courtès wrote:
> Hello Guilers!
> Today, it’s been 9 years since Guile 2.0 came out!
> It’s impressive how much has been accomplished since 2.0, and how what
> seemed like a pipe dream back then came into reality with 3.0.  I think
> Guile 2.0 started a renaissance of Guile, and it’s in bloom now.  :-)
> We used to have a “Guile potluck” for the anniversary, where people
> would bring their own hacks and virtually join for a party.  We missed
> it this year, but if there’s a nice hack that you’d like to share, now
> is a good time!
> Happy hacking with Guile!
> Ludo’.
> Attachments:
> * signature.asc

reply via email to

[Prev in Thread] Current Thread [Next in Thread]