Questions tagged [syntax-rules]

For questions about the syntax-rules macro facility of the Scheme programming language.

21 questions
12
votes
9 answers

How can I closely achieve ?: from C++/C# in Python?

In C# I could easily write the following: string stringValue = string.IsNullOrEmpty( otherString ) ? defaultString : otherString; Is there a quick way of doing the same thing in Python or am I stuck with an 'if' statement?
Jordan Parmer
  • 36,042
  • 30
  • 97
  • 119
11
votes
3 answers

What does the “|” sign mean in Python?

This question originally asked (wrongly) what does "|" mean in Python, when the actual question was about Django. That question had a wonderful answer by Triptych I want to preserve.
Vinko Vrsalovic
  • 330,807
  • 53
  • 334
  • 373
11
votes
4 answers

Sources for learning about Scheme Macros: define-syntax and syntax-rules

I've read JRM's Syntax-rules Primer for the Merely Eccentric and it has helped me understand syntax-rules and how it's different from common-lisp's define-macro. syntax-rules is only one way of implementing a syntax transformer within…
Kyle Burton
  • 26,788
  • 9
  • 50
  • 60
6
votes
1 answer

How are vector patterns used in syntax-rules?

I have been writing Common Lisp macros, so Scheme's R5Rs macros are a bit unnatural to me. I think I got the idea, except that I don't understand how one would use vector patterns in syntax-rules: (define-syntax mac (syntax-rules () ((mac #(a…
Jay
  • 9,585
  • 6
  • 49
  • 72
5
votes
1 answer

syntax-rules not completely hygienic?

I understand that syntax-rules is a hygienic macro system, but I do not understand why this happens: (define not (lambda (x) x)) (define-syntax nand (syntax-rules () ((_ a b) (not (and a b))))) (nand #f #t) ==> #f Now, if I had…
josh
  • 997
  • 1
  • 8
  • 13
5
votes
5 answers

Emacs Lisp syntax highlighting

I want to write a syntax highlighting extension for Emacs, but I Googling of variations on "emacs syntax highlight tutorial" have all failed. How do I go about learning how to write an Emacs highlighter? What good resources are there for learning…
Chris Lutz
  • 73,191
  • 16
  • 130
  • 183
5
votes
1 answer

Implicit currying in Scheme with syntax-rules?

Jeffrey Meunier has an implicit Curry macro here, which uses defmacro. I was wondering if someone has ever written this with syntax-rules?
Jay
  • 9,585
  • 6
  • 49
  • 72
4
votes
1 answer

Is it possible to define a syntax-rules macro in Common Lisp

I learned that it is easy to define a small macro in scheme by syntax-rules. Is it possible to define a syntax-rules macro which will return a list can be read by defmacro in Common Lisp? Which might work like this: (defmacro and (&rest rest) …
TsingHui
  • 49
  • 4
3
votes
1 answer

Guile `syntax-rules`: Misplaced Ellipsis in Form; How to Write this Macro with Two Ellipses?

I'm trying to, more or less, recreate a let construct via syntax-rules but it seems to be tripping on the use of two ellipses. I tried writting it out as so: (define-syntax if-let (syntax-rules () [(_ (([binding value] ...) …
Jaft
  • 43
  • 2
  • 8
3
votes
1 answer

Please refactor my macro in Scheme

I am learning hygiene and I tried to make a simple for loop in Scheme. I want to support three kinds of constructs as shown in example below (for i = 1 : (< i 4) : (++ i) (printf "Multiplication Table for ~s\n" i) (for j = 1 to 5 (printf…
unj2
  • 52,135
  • 87
  • 247
  • 375
2
votes
1 answer

Scheme's syntax-rules -- intermixing different syntax choices in `...`

Let's say I have a macro (define/custom (name (arg type) ...) body ...) that among other things expands to (define (name arg ...) body ...). That's easy. Now, I want to allow not only (arg type) to be passed as parameter, but simply arg. Alright, so…
Coderino Javarino
  • 2,819
  • 4
  • 21
  • 43
2
votes
2 answers

Scheme: How to expand a pattern with multiple variables in syntax-rules without parens

I'm trying to write a macro in Scheme for Picolisp style let expressions, let's call this macro let-slim. In order to be more terse (like Picolisp) I want their usage to look something like this when declaring only one variable (let-slim var-name…
Charlim
  • 521
  • 4
  • 12
2
votes
1 answer

Scheme macro pairwise processing question

(For now please ignore that what I'm after is un-Schemey, because this for a DSL aimed at non-programmers) I'd like to do something eqivalent to this: (pairwise key1 value1 key2 value2) Which would expand to this, m being another macro I've defined…
tommaisey
  • 449
  • 2
  • 10
2
votes
2 answers

How to control order of Scheme macro expansion?

I'm working with the Racket macro extension syntax-id-rules, that some other Scheme implementations provide under the name identifier-syntax. These let you specify macro expansions that will happen even when the defined identifier isn't in head…
dubiousjim
  • 4,722
  • 1
  • 36
  • 34
1
vote
1 answer

What Scheme special forms must the hygienic macro expander know about?

syntax-rules in Scheme are "hygienic" and "referentially transparent" and must preserve Scheme's lexical scoping. From my understanding, this means that during the macro expansion phase, the expander would need to know about lambda and define. The…
Flux
  • 9,805
  • 5
  • 46
  • 92
1
2