Questions tagged [reader-macro]

a way to program the Common Lisp reader

Reader macros provide a way to program the Common Lisp reader, which reads s-expressions and turns them into data. A typical use is to read new data types or to provide convenient notations.

39 questions
4
votes
3 answers

Clojure function literal with 'rest arguments' macro after 'discard' reader macro

I wanted a function literal in Clojure that can take any number of arguments, but doesn't actually use them. So I've discovered %& ('rest arg' for function literal) and #_ ('discard' reader macro). But how they work together surprises me: =>…
alex
  • 925
  • 1
  • 7
  • 9
4
votes
2 answers

Change default reader in common lisp

I wrote some function that could replace the function read of common lisp (defun my-read (stream &rest args) (declare (ignore args)) (funcall (my-get-macro-character (read-char stream)))) Is there a way to use this function as default reader?
cl-porky11
  • 339
  • 1
  • 11
3
votes
2 answers

Controlling the printing of special cons forms (e.g printing (function +) as #'+ etc)

I want some reader macros to print as as shortened expression that the macro understands. Lets say I want to extend the #' macro to take #'~[rest-of-symbol] and turn that into (complement #'rest-of-symbol). What controls how that is printed? On…
3
votes
1 answer

Readtable conflicts with cl-annot (cl-syntax, jonathan) and pythonic-string-reader

I like pythonic-string-reader to enable python-esque triple quotes: (defun hello () """docstring""" :hello) Use it: (ql:quickload "pythonic-string-reader") (pythonic-string-reader:enable-pythonic-string-syntax) it also works…
Ehvince
  • 17,274
  • 7
  • 58
  • 79
3
votes
1 answer

Can I get the boundaries of a macro in their expansion site?

I want to have the file locations and character positions of where a macroexpansion takes place in order to highlight the macro expansion in a GUI. For this, I want to be able to refer to the current position of a macro where an expansion takes…
ssice
  • 3,564
  • 1
  • 26
  • 44
3
votes
1 answer

Lisp loading error: undefined character in dispatch macro

I decided my birthday would be a good time to try and fix my Lisp problems. I've received a Lisp program from someone to run an experiment. It works well on his OS X environment. However, I can't get it to run on either Windows 7 or Ubuntu. The…
Gray
  • 71
  • 1
  • 2
3
votes
1 answer

Choose extension of :file component in asdf defsystem

I am 90% sure the answer is in this paragraph of the asdf documentation , but I seem unable to grok it. I am wondering if I am able to have source files that do not end in ".lisp" as file components. For example, usually I have something…
Baggers
  • 3,183
  • 20
  • 31
3
votes
1 answer

The necessity of quote in On Lisp's #[ read macro?

I am reading On Lisp and cannot make out why the code below has use a quote. Here is the excerpt from the text: Another character combination reserved for the user is #[. Figure 17.3 gives an example of how this character might be defined as a…
user1461328
  • 742
  • 2
  • 6
  • 13
3
votes
2 answers

How to force Common Lisp to treat numerals as symbol names?

I hope these codes (12 3.5 1e4) could be treated as three symbols (|12| |3.5| |1e4|) rather than three numbers. Can I fulfill this by setting the reader? Update: I have a collection of data which is organized as nested lists: (abc,d/e-f 12ab,…
SaltyEgg
  • 1,498
  • 1
  • 15
  • 26
2
votes
1 answer

Managing reader macros in Common Lisp

I want to define reader macros in such a way that they affect only a certain package/file. So far I was able to load those files with (let ((*readtable* (copy-readtable))) (load "file.lisp")) Is there a better way to do it?
sabof
  • 8,062
  • 4
  • 28
  • 52
2
votes
1 answer

read's recursive-p argument when used inside a reader macro

I have written a Common Lisp implementation of Scheme's s-expression comments (SRFI 62): (eval-when (:compile-toplevel :load-toplevel :execute) (set-dispatch-macro-character #\# #\; (lambda (stream char n) …
Flux
  • 9,805
  • 5
  • 46
  • 92
2
votes
1 answer

Common Lisp Read Macro for "lazy infix or," to destructure keywords

I have a Common Lisp reader macro to parse lazy/delayed declarations of an "or" relation, using infix syntax separated by pipe chacaters ("|") as well as standard list parentheses and keyword literals. Consider the form (:a :b|:c) -- it represents a…
2
votes
1 answer

What are limitations of reader macros in Common Lisp

I have my own Lisp interpreter in JavaScript that I work for some time now, and now I want to implement reader macros like in Common Lisp. I've created Streams (almost working except for special symbols like ,@ , ` ') but it freezes the browser for…
jcubic
  • 61,973
  • 54
  • 229
  • 402
2
votes
1 answer

Common Lisp No Dispatch Character Defined

I am currently reading the chapter on read-time macros from Paul Graham's "On Lisp" book. The problem I am encountering is the following. When I run one of his examples: (set-dispatch-macro-character #\# #\? #’(lambda (stream char1 char2) …
MadPhysicist
  • 5,401
  • 11
  • 42
  • 107
2
votes
1 answer

Read input into string in Lisp reader macro

I am trying to make a reader macro that would convert @this into "this". This is what I currently have: (defun string-reader (stream char) (declare (ignore char)) (format nil "\"~a\"" (read-line stream t nil t)) ) (set-macro-character…
iHuman
  • 105
  • 10