unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
Cc: guile-devel@gnu.org
Subject: Re: Typechecking I
Date: Sat, 20 Nov 2010 12:46:11 +0100	[thread overview]
Message-ID: <m3y68o1am4.fsf@unquote.localdomain> (raw)
In-Reply-To: <201011160010.53435.stefan.itampe@gmail.com> (Stefan Israelsson Tampe's message of "Tue, 16 Nov 2010 00:10:53 +0100")

Hi,

Just some superficial notes while reading your code :)

On Tue 16 Nov 2010 00:10, Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:

> (define-module  (language prolog typecheck equationalize)
>   #:use-module (srfi srfi-1                    )
>   #:use-module (ice-9 pretty-print             )  
>   #:use-module (ice-9 match                    )  
>   #:use-module (ice-9 receive                  )
>   #:export (equationalize check))

Thanks for making it depend on only modules in Guile :-)

The extra spaces before the close-parens should be removed, though.

> (define-syntax rlet

This is usually known as let-values, fwiw.

> (define (compute-type Const Code)  
>   (define (type? X) (and (symbol? X) (char-upper-case? (car (string->list (symbol->string X))))))

Try to keep your lines to less than 80 characters, please :)

>   (define (gen-map Code Bind Lam)
>     (match Code
>            ([X . L]     (gen-map X Bind (lambda (Bind) (gen-map L Bind Lam))))

The conventional indentation for this is:

      (match Code
        ([X . L]  ...))

If your emacs doesn't do this, add this to your .emacs:

  (put 'match 'scheme-indent-function 1)

> (define (check X)
>   (rlet ((A          X)
>          ((Ba Ea)   (equationalize '() '() A 'Texp)))
>         (pp A)

Likewise for rlet -- though it should be just let*-values, if it were a
macro of your own, you could add a similar block to the .emacs.

>   (match Expr
>          (['and X Y]   (let ((F1 (equationalize-bool Bind Eq X))
>                              (F2 (equationalize-bool Bind Eq Y)))
>                          (lambda (X) 
>                            (if X 
>                                (rlet (((Bind1 Eq1) (F1 #t))
>                                       ((Bind2 Eq2) (F2 #t)))
>                                   (values (union Bind1 Bind2) `(and ,Eq1 ,Eq2)))
>                                (rlet (((Bind1 Eq1) (F1 #f))
>                                       ((Bind2 Eq2) (F2 #f)))
>                                   (values (union Bind1 Bind2) `(or  ,Eq1 ,Eq2)))))))
>
>          (['or X Y]    (let ((F1 (equationalize-bool Bind Eq X))
>                              (F2 (equationalize-bool Bind Eq Y)))
>           

Here again, much more conventional would be

    (match Expr
      (['and X Y]
       (let ((F1 (equationalize-bool Bind Eq X))
             (F2 (equationalize-bool Bind Eq Y)))
         (lambda (X) 
           (if X 
               (rlet (((Bind1 Eq1) (F1 #t))
                      ((Bind2 Eq2) (F2 #t)))
                 (values (union Bind1 Bind2) `(and ,Eq1 ,Eq2)))
               (rlet (((Bind1 Eq1) (F1 #f))
                      ((Bind2 Eq2) (F2 #f)))
                 (values (union Bind1 Bind2) `(or ,Eq1 ,Eq2)))))))

      (['or X Y]
       ...))

Your style is has gotten a lot more readable, for which I am grateful :)
There is still some small ways to go yet, though.

Syntactically yours,

Andy
-- 
http://wingolog.org/



  reply	other threads:[~2010-11-20 11:46 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-21 20:23 The progress of hacking guile and prolog Stefan Israelsson Tampe
2010-11-03 23:43 ` Ludovic Courtès
2010-11-04  2:40   ` Noah Lavine
2010-11-10 17:55     ` Stefan Israelsson Tampe
2010-11-11 19:10       ` Noah Lavine
2010-11-11 16:26     ` Ludovic Courtès
2010-11-11 19:13       ` Noah Lavine
2010-11-11 19:15       ` Noah Lavine
2010-11-15 23:10     ` Typechecking I Stefan Israelsson Tampe
2010-11-20 11:46       ` Andy Wingo [this message]
2010-11-20 11:25     ` The progress of hacking guile and prolog Andy Wingo
2010-11-24  1:54       ` Noah Lavine
2010-11-24 16:45         ` Stefan Israelsson Tampe
2010-11-24 18:00         ` piper schemigan Stefan Israelsson Tampe
2010-11-24 20:18           ` Andreas Rottmann
2010-11-25 21:17           ` Ludovic Courtès
2010-11-26 22:18             ` Stefan Israelsson Tampe
2010-11-28 22:30               ` Guile-SCSH Ludovic Courtès
2010-11-28 23:02                 ` Guile-SCSH Stefan Israelsson Tampe
2010-11-28 23:24                   ` Guile-SCSH Jose A. Ortega Ruiz
2010-11-29 18:56                     ` Guile-SCSH Stefan Israelsson Tampe
2010-11-29 21:26                     ` http://gitorious.org/guile-scsh/guile-scsh Stefan Israelsson Tampe
2010-11-30 23:21                       ` Guile-Facade Ludovic Courtès
2010-11-25 21:26         ` The progress of hacking guile and prolog Ludovic Courtès
2010-11-26 16:41           ` Noah Lavine
2010-11-26 10:45         ` Andy Wingo
2010-11-20 11:26     ` Andy Wingo
2010-11-04 17:57   ` Stefan Israelsson Tampe
2010-11-05 21:19   ` Stefan Israelsson Tampe
2010-11-19 23:11     ` GLIL->C compilation Ludovic Courtès
2010-11-19 23:20       ` Stefan Israelsson Tampe
2010-11-19 23:56         ` Ludovic Courtès
2010-11-20 12:18           ` Andy Wingo

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=m3y68o1am4.fsf@unquote.localdomain \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=stefan.itampe@gmail.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).