Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Scheme Programming Language

how to generate n copies of code using macro?


hi

how to generate n copies of code using macro?

(bag-of (list (number-between 0 1) (number-between 0 1) (number-
between 0 1)) ...  )
I need to generate n copies "(number-between 0 1)".

Thanks.

On Apr 16, 7:54 am, dillog@gmail.com wrote:

> hi

> how to generate n copies of code using macro?

> (bag-of (list (number-between 0 1) (number-between 0 1) (number-
> between 0 1)) ...  )
> I need to generate n copies "(number-between 0 1)".

> Thanks.

Ok, no one wants offer a clean solution. I would just have to export
eval to toy interpreter and have the underlying scheme modify global-
env.

I don't understand your question. Perhaps you could give an example of
what you want.
On Apr 15, 7:54 pm, dillog@gmail.com wrote:

> how to generate n copies of code using macro?
> (bag-of (list (number-between 0 1) (number-between 0 1) (number-
> between 0 1)) ...  )
> I need to generate n copies "(number-between 0 1)".

Well, without macros, an equivalent expression would be:

(apply bag-of (map (lambda _ (number-between 0 1)) (iota n)))

iota is defined in SRFI-1, the rest is RnRS Scheme. There are many
other ways to write it; this one is short.

Once you've got that, you just need to apply it in the context of a
macro. For example, if you Scheme supports CL-style macros, you could
use:

(define-macro (bag n) `(bag-of ,@(map (lambda _ (number-between 0 1))
(iota ,n))))

Graham

On Apr 16, 10:52 am, "Graham" <graham.fawc@gmail.com> wrote:

> On Apr 15, 7:54 pm, dillog@gmail.com wrote:

> > how to generate n copies of code using macro?
> > (bag-of (list (number-between 0 1) (number-between 0 1) (number-
> > between 0 1)) ...  )
> > I need to generate n copies "(number-between 0 1)".

> Well, without macros, an equivalent expression would be:

> (apply bag-of (map (lambda _ (number-between 0 1)) (iota n)))

Oops, that should have been
(bag-of (map (lambda _ (number-between 0 1)) (iota n)))
and
(define-macro (bag n) `(bag-of ,(map (lambda _ (number-between 0 1))
(iota ,n))))

I mis-read your example as taking multiple arguments.

Graham

I think you ment:

(define-macro (bag n)
   `(bag of (list ,@(map (lambda (n)
                           '(number-between 0 1))
                         (iota n)))))

...

On Apr 16, 10:56 pm, "Graham" <graham.fawc@gmail.com> wrote:

I tried your code but get an error:
(define-macro (bag n) `(bag-of ,(map (lambda _ (number-between 0 1))
  (iota ,n)))
)

On Apr 16, 11:35 am, dillog@gmail.com wrote:

> On Apr 16, 10:56 pm, "Graham" <graham.fawc@gmail.com> wrote:
> I tried your code but get an error:
> (define-macro (bag n) `(bag-of ,(map (lambda _ (number-between 0 1))
>   (iota ,n)))
> )

> > stdin::53726: unquote: not in quasiquote in: (unquote n)

See Kjetil's correction. Sorry for the confusion, I shouldn't have
submitted my answer before testing it.

Graham

On Apr 16, 11:27 pm, "Kjetil S. Matheussen"

Which srfi is iota?
I've got an error:
reference to undefined identifier: iota

I've already loaded "(require (lib "list.ss" "srfi" "1"))"
Thanks.

dillog@gmail.com writes:
> Kjetil S. Matheussen wrote:
> > (define-macro (bag n)
> >    `(bag of (list ,@(map (lambda (n)
> >                            '(number-between 0 1))
> >                          (iota n)))))
> > ...

> Which srfi is iota?
> I've got an error:
> reference to undefined identifier: iota

Won't (make-list n '(number-between 0 1)) work the same? The contents
of (iota n) are being ignored here.
On Apr 16, 11:47 pm, dillog@gmail.com wrote:

This is strange:
iota was loaded and working but the macro won't work:

(require (lib "list.ss" "srfi" "1"))
(require (lib "defmacro.ss"))
(require (lib "1.ss" "srfi"))
(iota 6)
(define-macro (bag n)
   `(bag of (list ,@(map (lambda (n)
                           '(number-between 0 1))
                         (iota n)))))

(bag 1)
(bag 2)
(bag 3)
(bag 4)

> (0 1 2 3 4 5)
> > reference to undefined identifier: iota

I'm using mzscheme.
On Apr 17, 12:04 am, Jussi Piitulainen <jpiit@ling.helsinki.fi>
wrote:

> dillog@gmail.com writes:
> > Kjetil S. Matheussen wrote:
> > > (define-macro (bag n)
> > >    `(bag of (list ,@(map (lambda (n)
> > >                            '(number-between 0 1))
> > >                          (iota n)))))
> > > ...

> > Which srfi is iota?
> > I've got an error:
> > reference to undefined identifier: iota

> Won't (make-list n '(number-between 0 1)) work the same? The

(make-list 4 '(number-between 0 1))
((number-between 0 1) (number-between 0 1) (number-between 0 1)
(number-between 0 1))

This is not code, just text...

contents

On Apr 16, 12:04 pm, Jussi Piitulainen <jpiit@ling.helsinki.fi>
wrote:

> > Which srfi is iota?
> > I've got an error:
> > reference to undefined identifier: iota

> Won't (make-list n '(number-between 0 1)) work the same? The contents
> of (iota n) are being ignored here.

Yes. When I first read his question, I assumed he wanted to evaluate
the (number-between) expressions during macro-expansion, in which case
(make-list) wouldn't work. My initial (broken) version didn't quote
the number-between calls for that reason. Kjetil's version seems to be
what the OP wanted, though.

cheers,
G

On Apr 17, 12:19 am, "Graham" <graham.fawc@gmail.com> wrote:

The macro is still not working....I don't know what's wrong but iota
was indeed loaded...
(bag-of (list (number-between 0 1) (number-between 0 1) ))
(bag-of (list (number-between 0 1) (number-between 0 1) (number-
between 0 1) ))
(iota 6)
(define-macro (bag n)
   `(bag of (list ,@(map (lambda (n)
                           '(number-between 0 1))
                         (iota n)))))

Ok, I don't see how it's any different from the expression in the
macro definition,

    (map (lambda (n) '(number-between 0 1)) (iota n))

but if it makes you happy, here's a fake iota for when you don't care
of the contents of the list:

   (define iota make-list)

And here's one for when you do care:

   (define (iota n)
      (do ((n (- n 1) (- n 1))
           (v '() (cons n v)))
          ((negative? n) v)))

The macro expansion mechanism may be using a restricted language and
not seeing the iota. Try using only R5RS identifiers. You can always
define a iota locally at the point of use.

And fix the typo: bag of -> bag-of.

On Apr 17, 12:36 am, Jussi Piitulainen <jpiit@ling.helsinki.fi>
wrote:

I think the problem has nothing to do with iota....
It's probably to do with define-macro...because it can't seem to
"see" iota...
I've tried a few other examples but they all failed because define-
macro can't seem to use regular functions in expanding code....
On Apr 17, 12:52 am, dillog@gmail.com wrote:

Success!!!
The trick is that you have to provide the function yourself:

(define-macro (bag n)
  (define (iota n) (do ((n (- n 1) (- n 1)) (v '() (cons n v)))
((negative? n) v)))
   `(bag-of (list ,@(map (lambda (n)
                           '(number-between 0 1))
                         (iota n)))))
(bag 1)
(bag 2)
(bag 3)
(bag 4)

> > ((0) (1))
> ((0 0) (0 1) (1 0) (1 1))
> ((0 0 0) (0 0 1) (0 1 0) (0 1 1) (1 0 0) (1 0 1) (1 1 0) (1 1 1))
> ((0 0 0 0) (0 0 0 1) (0 0 1 0) (0 0 1 1) (0 1 0 0) (0 1 0 1) (0 1 1 0) (0 1 1 1) (1 0 0 0) (1 0 0 1) (1 0 1 0) (1 0 1 1) (1 1 0 0) (1 1 0 1) (1 1 1 0) (1 1 1 1))

Now I can stay with scheme, not thinking about jump ship to lisp :)

Get on with my coding. Thanks again.

dillog@gmail.com writes:
> Success!!!
> The trick is that you have to provide the function yourself:

> (define-macro (bag n)
>   (define (iota n) (do ((n (- n 1) (- n 1)) (v '() (cons n v)))
> ((negative? n) v)))
>    `(bag-of (list ,@(map (lambda (n)
>                            '(number-between 0 1))
>                          (iota n)))))

Then I would still try

  (define-macro (bag n)
     `(bag-of (list ,@(make-list n '(number-between 0 1)))));

it should work, unless you are loading make-list from a library that
define-macro does not see.

dillog@gmail.com skrev:

Since (bag 1) is expanded at macro expansion time, you need
to import iota to the syntax environment (and not to the
normal op level). That is, use:

(require-syntax (lib "1.ss" "srfi"))

--
Jens Axel Sgaard

On Apr 17, 2:46 am, Jens Axel Sgaard <use@soegaard.net> wrote:

Where is "require-syntax"?
reference to undefined identifier: require-syntax
Thanks.

dillog@gmail.com skrev:

> Where is "require-syntax"?
> reference to undefined identifier: require-syntax

What language are you using?

--
Jens Axel Sgaard

On Apr 17, 3:10 am, Jens Axel Sgaard <use@soegaard.net> wrote:

> dillog@gmail.com skrev:

> > Where is "require-syntax"?
> > reference to undefined identifier: require-syntax

> What language are you using?

Just regular mzscheme:

MY_UNPACK plt-360-src-unix.tgz
cd plt-360/src
./configure --prefix=/usr
make clean ; make || sleep 99999999
make install
# mzscheme -f <file>, --load <file>
# mzscheme -f /lfs/scheme/my_test.sc

dillog@gmail.com skrev:

> On Apr 17, 3:10 am, Jens Axel Sgaard <use@soegaard.net> wrote:
>> dillog@gmail.com skrev:

>>> Where is "require-syntax"?
>>> reference to undefined identifier: require-syntax
>> What language are you using?

> Just regular mzscheme:

Sorry. I wrote require-syntax, but erm meant require-for-syntax.

--
Jens Axel Sgaard

On Apr 17, 3:39 am, Jens Axel Sgaard <use@soegaard.net> wrote:

> dillog@gmail.com skrev:

> > On Apr 17, 3:10 am, Jens Axel Sgaard <use@soegaard.net> wrote:
> >> dillog@gmail.com skrev:

> >>> Where is "require-syntax"?
> >>> reference to undefined identifier: require-syntax
> >> What language are you using?

> > Just regular mzscheme:

> Sorry. I wrote require-syntax, but erm meant require-for-syntax.

> --
> Jens Axel Sgaard

Is there a "syntaxed" version of amb?
Please read my disaster thread. What exactly do I have to do to get
the code working. I don't want to rewrite my interpreter in CPS and
support call/cc right now. (I don't know how much work that is gonna
take.) Does every one on this planet have to reimplement scheme to get
some magic out of it? aarrrggghhh.
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc