Re: How to update an agrument passed by name in scheme
- From: Anton van Straaten <anton@xxxxxxxxxxxxxxxx>
- Date: Wed, 01 Feb 2006 06:06:18 GMT
artejera@xxxxxxxxx wrote:
Well, in spite of 30 years of programming imperative languages ( or because of that ...) I can't figure out "How to update an agrument passed by name in Scheme".
I'm trying to use Scheme to implement an interpreter of a prototype language, and it has many advantages, but this point is beating me
Scheme arguments are passed by value, and there are no pointers as such; to pass by name, you need a macro. Here's an example, in standard (R5RS) Scheme, of a macro "inc!" which increments the variable passed to it:
(define-syntax inc!
(syntax-rules ()
((inc! x)
(set! x (+ x 1)))))(define b 4) (inc! b) (display b)(newline)
=> 5
Scheme's syntax-rules macros rely on pattern-matching, so may take a little getting used to, but they're quite simple to use - so simple that no-one's ever bothered to write a nice gentle introduction to them (prove me wrong, someone!) Here's one explanation of them:
http://home.comcast.net/~prunesquallor/macro.txt
Depending on what you need to do, another way to do this kind of thing is to box the value, using either your Scheme implementation's box type (if it has one), or some other mutable container such as a pair or single-element vector.
Anton .
- Follow-Ups:
- Re: How to update an agrument passed by name in scheme
- From: Joe Marshall
- Re: How to update an agrument passed by name in scheme
- References:
- How to update an agrument passed by name in scheme
- From: artejera
- How to update an agrument passed by name in scheme
- Prev by Date: How to update an agrument passed by name in scheme
- Next by Date: Re: Stair-Stepping in style
- Previous by thread: How to update an agrument passed by name in scheme
- Next by thread: Re: How to update an agrument passed by name in scheme
- Index(es):
Relevant Pages
|