Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

How do I define a symbol-macro in Scheme?

Name: Anonymous 2011-11-19 21:27


(require mzlib/defmacro)
(define-macro 16-bit-mask #xFFFF)

doesn't work.

Name: Anonymous 2011-11-19 21:33

Common Lisp has DEFINE-SYMBOL-MACRO.

Name: Anonymous 2011-11-19 21:46

Scheme is a toy language, you cant expect it to offer mature macros system.

Name: Anonymous 2011-11-19 22:01

Here is an ugly and inefficient hack to make it work.

(defmacro symbol-macrolet (mcrsymbs . body)

  (let ([form (map (lambda(mcr)

                     (cons (car mcr) (cadr mcr)))

                   mcrsymbs)])

    (racket-eval (dynamic-transformer `(begin . ,body)

                                      #:local-macrosymbols form))))

Name: Anonymous 2011-11-20 15:23

>>1
(define-for-syntax 16-bit-mask #xFFFF)

Name: Anonymous 2011-11-20 16:06

#define BIT_MASK_16 0xFFFF

Name: Anonymous 2011-11-20 16:45

(define-syntax bit-mask (identifier-syntax #xFFFF))
Identifiers can't begin with a digit.

Name: Anonymous 2011-11-20 18:27

>>7

Some schemes allow for it. I don't know if it is part of the standard or not.


(define 3d-point (vector 2 4 3))

Name: Anonymous 2011-11-20 19:18

>>8
It wouldn't matter if it were, since no one implements the standards without exception.

Name: Anonymous 2011-11-20 19:39

>>8
R6RS explicitly forbid usage of digits for the first character of as identifier.
See :

4.2.4 Identifiers
[...]In general, a sequence of letters, digits, and “extended alphabetic characters” is an identifier when it begins with a character that cannot begin a representation of a number object.[...]

Also, <identifier> in "4.2.1  Formal account".

Name: Anonymous 2011-11-20 19:51

>>10

scm is too cool for the standard. It seems to accept anything that fails to be a literal of some kind as a symbol.


SCM version 5e5, Copyright (C) 1990-2006 Free Software Foundation.
SCM comes with ABSOLUTELY NO WARRANTY; for details type `(terms)'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `(terms)' for details.
;loading /usr/share/slib/require
;done loading /usr/share/slib/require.scm
;loading /usr/share/slib/require
;done loading /usr/share/slib/require.scm
;loading /usr/lib/scm/Link
;done loading /usr/lib/scm/Link.scm
;loading /usr/lib/scm/Transcen
;done loading /usr/lib/scm/Transcen.scm
(define 234234234@@##12443234@*.... 45)
#<unspecified>
234234234@@##12443234@*....
45
(define 0xFFFF 5)
#<unspecified>
0xFFFF
5
(define (foldl op lis id) (letrec ((helper (lambda (lis id) (if (null? lis) id (helper (cdr lis) (op id (car lis))))))) (helper lis id)))
#<unspecified>
(foldl * '(1 2 3 4 5) 1)
120
(define (1~ 2~ 3~ 4~) (letrec ((5~ (lambda (3~ 4~) (if (null? 3~) 4~ (5~ (cdr 3~) (2~ 4~ (car 3~))))))) (5~ 3~ 4~)))
#<unspecified>
(~1 * '(1 2 3 4 5) 1)

;ERROR: "/usr/lib/scm/Iedline.scm": unbound variable:  ~1
; in expression: (~1 * (quote (1 2 3 4 5)) 1)
; in top level environment.
;STACK TRACE
1; (#@let ((tail (#@lambda (c) (#@if (#@char? #@c) #@c (#@let* (( ...
2; (~1 * (quote (1 2 3 4 5)) 1)

(1~ * '(1 2 3 4 5) 1)
120

Name: Anonymous 2011-11-20 19:52

>>10
It is like that back to R4RS. I don't have copies of earlier standards to check. It's probably always been like that.

Name: Anonymous 2011-11-20 23:34

>>5
Ok. I did following.

(define-macro (define-const sym expr)
  `(define-syntax (,sym stx-obj) #',expr))


Dunno why define-macro cant that.

>>10
DrRacket aint that picky.

Welcome to DrRacket, version 5.2 [3m].
Language: Determine language from source [custom]; memory limit: 128 MB.
'14-88^xpert-1335per
'14-88^xpert-1335per

Don't change these.
Name: Email:
Entire Thread Thread List