unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: tomas@tuxteam.de
Cc: Andy Wingo <wingo@pobox.com>, guile-devel <guile-devel@gnu.org>
Subject: Re: Guile Assembler
Date: Tue, 23 Jun 2015 23:33:06 +0200	[thread overview]
Message-ID: <CAMFYt2beZyQmfd_ANf3n0gZAcTV3m=F2k-Spk=6KiJmmOGQ2Sg@mail.gmail.com> (raw)
In-Reply-To: <20150623094526.GA20821@tuxteam.de>

[-- Attachment #1: Type: text/plain, Size: 2631 bytes --]

>
> > > Hm. Where's the difference to Guile's define? And why do you have
> double
> > > parentheses in your example?
> > >
> > > Still a bit lost.
> >
> > hmm...do you read the pasted code in the repo? ;-)
>
> Not yet, I must admit. But nevermind, got it. It looks like a definition
> for a parametric func or for a half-curried func, depending on how you
> squint at it ;-)
>
> That explains the second set of parens.
>

Hi,
sorry to answer that late, but I erroneously sent the previous answer only
to Nala.

I have another project (in another repo) which provides the (extra common)
module, which redefines "define" and "lambda" forms (among others):

https://bitbucket.org/panicz/slayer/src/cbfb3187edaba890b12b307d84bb9c4538407d20/guile-modules/extra/common.scm?at=default

(The module is rather huge -- it is a bag that I carry around)

The modification of "define" originates, I believe, from the book
"Structure and Interpretation of Classical Mechanics" by Gerald Sussman and
Jack Wisdom [1], but I stole that idea directly from Guile's (ice-9
curried-definitions) module [2]. The idea is that

(define ((f x) y)
  (list x y))

is equivalent to

(define f
  (lambda (x)
    (lambda (y)
       (list x y))))

This behaviour is consequent with the idea that

(define (g x)
  (* x x))

should be equivalent to

(define g
  (lambda (x)
    (* x x)))

The derivative variants are easier to read, because they make it apparent,
that e.g. (g 5) can be substituted with (* 5 5), and -- similarly -- ((f 2)
3) can be substituted with (list 2 3).

The other difficulty is that the original function header looked like this:

(define ((number/base base) (l ...))

so that the form of the second argument is "(l ...)". This is because the
(extra common) module allows to destructure the arguments using the (ice-9
match) pattern matcher, so that the above header is actually equivalent to

(define number/base
  (lambda (base)
    (lambda x
      (match x
        ((l ...)

In practice that form of argument doesn't do much. It just tells the reader
that the argument is a proper list (because only a proper list matches such
pattern)

Similarly, I could write code like

(map (lambda ((a . b)) (+ a b)) '((1 . 2)(3 . 4)(5 . 6)))

I also use that trick with let and let* forms:

(let (((x y) '(1 2)))
  (+ x y))

In addition, the module allows me to use the "let" and "let*" forms with
multiple values:

(let ((a (b c) (values 1 '(2 3))))
  (+ a b c))

Best regards

[1]
http://mitpress.mit.edu/sites/default/files/titles/content/sicm/book-Z-H-11.html
[2]
https://www.gnu.org/software/guile/manual/html_node/Curried-Definitions.html

[-- Attachment #2: Type: text/html, Size: 4199 bytes --]

  reply	other threads:[~2015-06-23 21:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-22 18:32 Guile Assembler Sjoerd van Leent
2015-06-22 20:49 ` Panicz Maciej Godek
2015-06-23  6:28   ` Nala Ginrut
2015-06-23  9:12     ` tomas
2015-06-23  9:19       ` Nala Ginrut
2015-06-23  9:27         ` tomas
2015-06-23  9:30           ` Nala Ginrut
2015-06-23  9:45             ` tomas
2015-06-23 21:33               ` Panicz Maciej Godek [this message]
2015-06-24  8:34                 ` tomas
2015-06-24  9:44                   ` Panicz Maciej Godek
2015-06-24 11:59                     ` dsmich
2015-06-24 21:54                     ` Panicz Maciej Godek
2015-09-04  0:54                       ` Mark H Weaver
2015-09-04  9:31                         ` Panicz Maciej Godek
2015-09-04 16:58                           ` Mark H Weaver
2015-06-23 12:54         ` Barry Fishman
2015-06-23 21:00           ` Panicz Maciej Godek
2015-06-24  2:18             ` Barry Fishman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMFYt2beZyQmfd_ANf3n0gZAcTV3m=F2k-Spk=6KiJmmOGQ2Sg@mail.gmail.com' \
    --to=godek.maciek@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=tomas@tuxteam.de \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).