Re: [Chicken-users] unbound variable: or

2015-05-30 Thread John Cowan
Michele La Monaca scripsit:

 Gambit has it. Too bad Chicken 4 dropped it.

You're right; I was too hasty.  There are a number of other Schemes
that accept it also.  However, it does not fit into the {define-syntax,
let-syntax, let*-syntax, letrec-syntax} set provided by all post-R4RS
Schemes.

 Let’s say someone had the (bad?) idea to masquerade/embed it in other
 more baroque forms. For example in Chicken you have to write:

Yes, if explicit renaming is available (generally the case except in
Schemes that do syntax-case) then you can simulate it by not renaming
anything.  Syntax-case can sort of simulate it, but not 100% accurately.

I'll have more details on who does what posted later when I get my
suite of Schemes working again: at the moment, some of them have
bit-rotted.

 Define-macro is the most basic, no-frills macro system and the one
 which will give you the most profound understanding of what a macro is
 and is not. Oh, and it is quite powerful. I’ve used Gambit to
 practice. Only when you dominate it, I suggest to move on to
 syntax-rules. The latter works at a higher layer (see below), enforces
 hygiene and introduces you to pattern matching (which is not a macro
 specific topic).

That's like saying you should master assembly language before moving on
to a high-level languge like Scheme, because it gives you the most
profound understanding of what a computer does and is quite powerful.
These things are true, but assembly language and low-level macros
also give you the opportunity not only to shoot yourself in the foot,
but to shoot your users in the foot as well: they will write very
reasonable looking macro calls that just won't work because of the
lack of hygiene.  Gensym-renaming helps with half of hygiene, but
there's nothing you can do in writing your macro to provide for the
other half of it.

-- 
John Cowan  http://www.ccil.org/~cowanco...@ccil.org
The Unicode Standard does not encode idiosyncratic, personal, novel,
or private use characters, nor does it encode logos or graphics.

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] unbound variable: or

2015-05-30 Thread chi
On 05/30/2015 07:02 AM, Peter Bex wrote:
 As has been pointed out time and again, it is fundamentally broken.

Generally when that is true, you can link to a prepared document explaining it
clearly and unambiguously. Since it has been carefully explained, and rehashed
to the point of ad nauseum, could you link to where it is explained why
define-macro is fundamentally broken? Because I can't find such a document for
the life of me.

I mean it's obvious define-macro is a bad idea, because
(define-macro (foo bar)
  '(define x 23))

(define x 42)
(foo bar)
(write x)
(newline)

...is confusing as all heck. But I can't find anywhere that really explains why
that's _fundamentally_ broken, not just ugly.

Incidentally, I'm pretty sure define-syntax isn't hygenic. syntax-rules is
hygenic. You can still ruin yourself with define-syntax, like:

(define-syntax a
  (lambda (form rename compare)
'(define b 23)))

(define b 42)
(a)
(write b)
(newline)

...and I would like to state for the record that even defining hygenic syntax is
a pretty ruinous idea. You have to be very careful of what you're doing, and
confident that it's a good idea, because it is literally impossible for someone
to tell what your program means without first calculating all of the syntax
rules you have defined in their head. It's so easy to mess with syntax in
Scheme, and that can be a double edged sword, where the code you produce is
completely inscrutable because nobody can figure out what the final result of
syntax producing syntax producing syntax will be.

It is kind of fun that you can write an uncomputable program though.

(define-syntax make-cool-program
  ;; this is gonna be totally awesome guys
  (lambda (form rename compare)
(let loop ()
  (loop

(make-cool-program)

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] use vs uses?

2015-05-30 Thread chi
(use a) versus (declare (uses a)) what's the differences between those?

(use a) will load module...library...module... what do you call the thing that
(use) loads? Is it a library or a module?

...whereas (declare (uses a)) just requires that library to be loaded I think?

But then wouldn't (import a) and (declare (uses a)) be equivalent? Are they?

But (import) imports modules that are already loaded from libraries. Are
libraries and modules equivalent? Can a library have more than one module? If a
library has more than one module, then how does (use amodule) know to load the
same library as (use bmodule)? Do modules have to be named after libraries?
What's the difference between a module inline in your code and a library?
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] unbound variable: or

2015-05-30 Thread Peter Danenberg
Quoth chi on Sweetmorn, the 5th of Confusion:
 I mean it's obvious define-macro is a bad idea.

I wonder why no one ever mentions Juergen Lorenz' wonderful define-macro:

  http://api.call-cc.org/doc/bindings#def:define-macro

Looks like it's syntactic sugar around implicit-renaming; gives one the 
apparent ability to write low-level-like syntactic-transformations, though, 
without worrying about injection, c.

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] unbound variable: or

2015-05-30 Thread Peter Bex
On Fri, May 29, 2015 at 10:23:03PM -0400, John Cowan wrote:
 Googling for syntax-rules will point you to a lot of basic tutorials.
 When you want something more advanced, look for JRM's Syntax-rules
 Primer for the Mildly Eccentric.  Read that until you have trouble
 understanding it; you now know as much as you can absorb.  Go back to
 it later when you need more.

There are also some useful resources in our tutorials section on the
wiki: http://wiki.call-cc.org/tutorials

Cheers,
Peter


signature.asc
Description: Digital signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] unbound variable: or

2015-05-30 Thread Peter Bex
On Sat, May 30, 2015 at 03:42:41PM +0200, Michele La Monaca wrote:
 On Sat, May 30, 2015 at 4:23 AM, John Cowan co...@mercury.ccil.org wrote:
  Jinsong Liang scripsit:
 
  I want to learn some basic macro programming in Chicken. However, it seems
  there are multiple macro definition APIs in Chicken: define-syntax,
  syntax-rules, syntax-case, define-macro. Which one should I start with?
 
  Define-macro is completely obsolete and not supported in Chicken 4 or
  any modern Scheme.
 
 Gambit has it. Too bad Chicken 4 dropped it.
 
 I don’t think describing define-macro obsolete” is 100% correct.

As has been pointed out time and again, it is fundamentally broken.
See also below:

 Let’s say someone had the (bad?) idea to masquerade/embed it in other
 more baroque forms. For example in Chicken you have to write:
 
 (define-syntax apply-any
   (er-macro-transformer
 (lambda (form rename compare)
   (let ((x (cadr form)) (lst (caddr form)))
 (eval `(cons ',x ,lst))
 
 instead of:
 
 (define-macro apply-any
  (lambda (x lst)
(eval `(cons ‘,x ,lst

Looks like you are mixing up two things: on one hand, define-macro
offers the syntactic convenience of not having to pick apart the input
form.  On the other hand, define-macro does not support hygienic
renaming at all (except for gensym, which only works on identifiers
created by the macro itself).

If it's the syntactic convenience you're after, take a look at the
bindings egg by Juergen Lorenz.  It offers various improvements
on the basic er-macro-transformer and ir-macro-transformer syntax.

 Oh, and it is quite powerful. I’ve used Gambit to
 practice. Only when you dominate it, I suggest to move on to
 syntax-rules. The latter works at a higher layer (see below), enforces
 hygiene and introduces you to pattern matching (which is not a macro
 specific topic).
 
 (define-syntax apply-any
   (syntax-rules ()
 ((_ x lst) (eval (cons 'x lst)
 
 (define l '(#f (+ 1 2) (print hello)))
 
 (apply-any or l)
 
 = 3
 
 (apply-any + (list 1 2 3))
 
 = 6
 
 (let ((x 9)) (apply-any or '(#f (+ x 1) (print hello
 
 Error: unbound variable: x
 
 Oops.

Eval does not have access to the lexical scope where it is
invoked.

Cheers,
Peter


signature.asc
Description: Digital signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] unbound variable: or

2015-05-30 Thread Michele La Monaca
On Sat, May 30, 2015 at 4:23 AM, John Cowan co...@mercury.ccil.org wrote:
 Jinsong Liang scripsit:

 I want to learn some basic macro programming in Chicken. However, it seems
 there are multiple macro definition APIs in Chicken: define-syntax,
 syntax-rules, syntax-case, define-macro. Which one should I start with?

 Define-macro is completely obsolete and not supported in Chicken 4 or
 any modern Scheme.

Gambit has it. Too bad Chicken 4 dropped it.

I don’t think describing define-macro obsolete” is 100% correct.
Let’s say someone had the (bad?) idea to masquerade/embed it in other
more baroque forms. For example in Chicken you have to write:

(define-syntax apply-any
  (er-macro-transformer
(lambda (form rename compare)
  (let ((x (cadr form)) (lst (caddr form)))
(eval `(cons ',x ,lst))

instead of:

(define-macro apply-any
 (lambda (x lst)
   (eval `(cons ‘,x ,lst

Define-macro is the most basic, no-frills macro system and the one
which will give you the most profound understanding of what a macro is
and is not. Oh, and it is quite powerful. I’ve used Gambit to
practice. Only when you dominate it, I suggest to move on to
syntax-rules. The latter works at a higher layer (see below), enforces
hygiene and introduces you to pattern matching (which is not a macro
specific topic).

(define-syntax apply-any
  (syntax-rules ()
((_ x lst) (eval (cons 'x lst)

(define l '(#f (+ 1 2) (print hello)))

(apply-any or l)

= 3

(apply-any + (list 1 2 3))

= 6

(let ((x 9)) (apply-any or '(#f (+ x 1) (print hello

Error: unbound variable: x

Oops.

I’m definitely not an expert of the topic so take my suggestions for
what you think they are worth.

Regards,
Michele

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] unbound variable: or

2015-05-30 Thread Michele La Monaca
On Sat, May 30, 2015 at 4:02 PM, Peter Bex pe...@more-magic.net wrote:
 On Sat, May 30, 2015 at 03:42:41PM +0200, Michele La Monaca wrote:
 On Sat, May 30, 2015 at 4:23 AM, John Cowan co...@mercury.ccil.org wrote:
  Jinsong Liang scripsit:
 
  I want to learn some basic macro programming in Chicken. However, it seems
  there are multiple macro definition APIs in Chicken: define-syntax,
  syntax-rules, syntax-case, define-macro. Which one should I start with?
 
  Define-macro is completely obsolete and not supported in Chicken 4 or
  any modern Scheme.

 Gambit has it. Too bad Chicken 4 dropped it.

 I don’t think describing define-macro obsolete” is 100% correct.

 As has been pointed out time and again, it is fundamentally broken.

Ok, I trust you then.

 Looks like you are mixing up two things: on one hand, define-macro
 offers the syntactic convenience of not having to pick apart the input
 form.  On the other hand, define-macro does not support hygienic
 renaming at all (except for gensym, which only works on identifiers
 created by the macro itself).

I have no use of renaming in my example so I am mixing up nothing.
BTW, I am not interested in protecting eval and cons if you were
asking.

 If it's the syntactic convenience  you're after, take a look at the 
 bindings egg by Juergen Lorenz.

So you first mess with the define-macro syntax then redirect me to an
egg to fix it up again. No thanks.

  It offers various improvements
 on the basic er-macro-transformer and ir-macro-transformer syntax.

 (let ((x 9)) (apply-any or '(#f (+ x 1) (print hello

 Error: unbound variable: x

 Oops.

 Eval does not have access to the lexical scope where it is
 invoked.

Exactly. But it looks like you missed the point. Hint: reconsider the
where word.

Regards,
Michele

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users