Discussion:
[Larceny-users] using macros to handcode random walk in arbitrary dimension
Marijn Schouten (hkBst)
2009-05-05 16:18:12 UTC
Permalink
Hi,

I am trying to write a program that will iterate over all random walks of a
certain fixed depth on a grid of a certain dimension DIM. There are exactly
(expt (* 2 (DIM)) depth)) such random walks and I would like to calculate the
mean squared length of them at a certain depth. The answer is depth. The
algorithm should thus act as the identity function on natural numbers, if given
depth and returning the mean squared length of random walks of that depth.

The function

(define (walk-f depth)
(let step ((d 0) (x 0) (y 0) #;(z 0))
(cond ((< d depth)
(let ((d+1 (+ d 1)))
(+
(step d+1 (+ x 1) y)
(+
(step d+1 (- x 1) y)
(+ (step d+1 x (+ y 1))
(step d+1 x (- y 1))) ))))
(else
(L2-norm x y)))))

calculates the total squared length. Assuming dimension 2 I performed some
optimizations. I have written syntax-case macro code that should construct this
function for arbitrary dimension, except I cannot get it to work. I have
attached the complete program (68 lines) with the offending code commented out.

I would really appreciate some help with this.

Thanks,

Marijn
--
If you cannot read my mind, then listen to what I say.

Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML
<http://www.gentoo.org/proj/en/lisp/>, #gentoo-{lisp,ml} on FreeNode
Felix Klock
2009-05-05 16:38:02 UTC
Permalink
Marijn (cc'ing larceny-users)-
Post by Marijn Schouten (hkBst)
I have written syntax-case macro code that should construct this
function for arbitrary dimension, except I cannot get it to work. I have
attached the complete program (68 lines) with the offending code commented out.
It looks to me like you are invoking larceny in a manner where it will
start up in its default mode which is an R5RS read-eval-print loop
(plus some Larceny-specific extensions).

This default mode is different from Larceny's ERR5RS and R6RS modes.
In particular, there is *no* support for syntax-case in Larceny's
default mode.

Would that explain the problems you are experiencing?

----

You will have to decide whether you want to switch to running Larceny
in a different mode (such as its ERR5RS mode), which will require some
changes to your code, or if you want to switch to using Larceny's
default macro system (where the only support for procedural macros is
its explicit-renaming transformer macros [1]), which will require an
entirely different set of changes to your code.

-Felix

[1] William D Clinger, "Hygienic macros through explicit renaming."
In Lisp Pointers IV(4), 25-28, December 1991. ftp://ftp.cs.indiana.edu/pub/scheme-repository/doc/prop/exrename.ps.gz
Marijn Schouten (hkBst)
2009-05-06 13:06:31 UTC
Permalink
Post by Felix Klock
Marijn (cc'ing larceny-users)-
Post by Marijn Schouten (hkBst)
I have written syntax-case macro code that should construct this
function for arbitrary dimension, except I cannot get it to work. I have
attached the complete program (68 lines) with the offending code commented out.
It looks to me like you are invoking larceny in a manner where it will
start up in its default mode which is an R5RS read-eval-print loop (plus
some Larceny-specific extensions).
This default mode is different from Larceny's ERR5RS and R6RS modes. In
particular, there is *no* support for syntax-case in Larceny's default
mode.
Would that explain the problems you are experiencing?
Ah, yes that would explain larceny's behavior.
Post by Felix Klock
----
You will have to decide whether you want to switch to running Larceny in
a different mode (such as its ERR5RS mode), which will require some
changes to your code, or if you want to switch to using Larceny's
default macro system (where the only support for procedural macros is
its explicit-renaming transformer macros [1]), which will require an
entirely different set of changes to your code.
Thanks. So you're saying that ERR5RS mode supports syntax-case macros? How do I
enable it? The following doesn't work:

$ larceny -err5rs -- stripped-randomwalk.scm -e "(define pp pretty-print)" -e
"(main 10)" -e "(quit)"
Larceny v0.97a4 (alpha test) (Mar 13 2009 15:30:01, precise:Linux:unified)
ERROR detected during macro expansion:
Malformed syntax-rules
(lambda (stx) (syntax-case stx () ---
Post by Felix Klock
-Felix
[1] William D Clinger, "Hygienic macros through explicit renaming." In
Lisp Pointers IV(4), 25-28, December 1991.
ftp://ftp.cs.indiana.edu/pub/scheme-repository/doc/prop/exrename.ps.gz
That seems to be only the first page of that article.

Thanks,

Marijn

- --
If you cannot read my mind, then listen to what I say.

Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML
<http://www.gentoo.org/proj/en/lisp/>, #gentoo-{lisp,ml} on FreeNode
Loading...