Skip to main content
Share Your Experience: Take the 2024 Developer Survey
15 votes

How can a compiler be written for a language that allows rewriting code at runtime (such as Lisp macros)?

You are confusing two different concepts in your question. Macros are not about compiling code at runtime. They are the exact opposite: they are about running code at compile time. So, in this case, ...
Jörg W Mittag's user avatar
12 votes
Accepted

How can a compiler be written for a language that allows rewriting code at runtime (such as Lisp macros)?

Macros have the advantage to be expanded at compile time The idea of Lisp macros is to be able to fully expand them at compile time. Then no compiler is needed at runtime. Most Lisp systems allow you ...
Rainer Joswig's user avatar
9 votes

How can a compiler be written for a language that allows rewriting code at runtime (such as Lisp macros)?

A typical "compiling lisp" will include the compiler in a bundled image. Furthermore, most (although not all) function calls are done through symbol indirections (basically, when the compiler sees (+ ...
Vatine's user avatar
  • 4,269
7 votes

What practical problem results from lack of hygienic macros in Clojure?

The advantage of hygienic macros is not one of language capability -- you can write macros that have good hygiene using gensym and careful quoting/unquoting at the right times. However, hygienic ...
Nathan Davis's user avatar
6 votes
Accepted

Best Practice - Where to declare variables in Common Lisp?

Your approach is correct: we bind (rather than declare, as in other languages) variables exactly where we need them. (In your case, however, you are using h-offset in the 1st half of your function, ...
sds's user avatar
  • 861
6 votes

In what area is LISP's macro better than Ruby's "ability" to create DSL

Ruby's DSLs aren't DSLs at all, and I absolutely hate using them because their documentation flat-out lies about how they really work. Let's take ActiveRecord for example. It allows you to "declare" ...
Throw Away Account's user avatar
5 votes

Can Lisp keywords be protected?

In Common Lisp, all symbols in the package COMMON LISP are protected by the standard. It says that redefining the package or the symbols in the package has undefined consequences. Which means, ...
Rainer Joswig's user avatar
5 votes
Accepted

In which order should lisp functions be defined?

For Common Lisp I'm using something like this: files are organized in systems and subsystems (see for example ASDF as a tool for that) you can put everything in one file, but that takes some care ...
Rainer Joswig's user avatar
4 votes

How can a compiler be written for a language that allows rewriting code at runtime (such as Lisp macros)?

Clearly, runtime code generation is incompatible with ahead-of-time compilation. Therefore, the language runtime environment must include some mechanism to dynamically execute code: either an ...
amon's user avatar
  • 134k
4 votes

How can a compiler be written for a language that allows rewriting code at runtime (such as Lisp macros)?

Yes. The runtime have to include an interpreter or compiler. This is why eval is traditionally is a feature of interpreted languages, since the runtime of these languages (by definition) contains an ...
JacquesB's user avatar
  • 59.7k
4 votes
Accepted

Why are Lisp programs a sequence of S-expressions and not a single list?

One of the reasons is that a single s-expression is slighty less practical in actual programming in many cases. Remember, the evaluator in Lisp works like this: it reads a form and then evaluates it. ...
Rainer Joswig's user avatar
3 votes
Accepted

Why are functions in Emacs so large?

Length of named code blocks might be a good metric. We know that at more lines of code, more potential errors※1. This is easily understood as each line of code being a possible point of failure. In ...
Theraot's user avatar
  • 9,151
3 votes

Do non-pure interpreters still make the guarantees of functional programming?

The guarantees provided by a functional programming language apply to the behavior of programs written in that language, not the implementation itself. "No side effects" means that there are no side ...
Sean Lynch's user avatar
3 votes

How useful are Lisp macros?

Here's one I use for debugging (in Clojure): user=> (defmacro print-var [varname] `(println ~(name varname) "=" ~varname)) #'user/print-var => (def x (reduce * [1 2 3 4 5])) #'user/x => (...
Jonas Kölker's user avatar
3 votes

In which order should lisp functions be defined?

Common Lisp has both COMPILE and COMPILE-FILE. An implementation like SBCL does not warn about undefined function if you compile the whole file, for example. Under slime, C-c M-k does not trigger a ...
coredump's user avatar
  • 5,965
3 votes

Can Lisp keywords be protected?

Symbols are not protected because they don't need to be. Some languages have reserved names because their syntax cannot tolerate having a class named "class", even though technically you could avoid ...
coredump's user avatar
  • 5,965
2 votes

Can Lisp keywords be protected?

Why aren't lisp keywords protected? Because they aren't keywords, they are just library functions like any other. Where can this be useful, It means that you, as a user, have the same power as ...
Jörg W Mittag's user avatar
2 votes

Why isn't Lisp more widespread?

I've been wondering the same for long, and I even went to Lisp conferences to try to understand what is this Lisp "dark side" that keeps everyone from adopting it. I've found no complete decent ...
6502's user avatar
  • 751
2 votes

Python decorators and Lisp macros

A decorator (be it in Python or in any other - functional programming - language) is just a function which accepts an original (to-be-decorated) function (and sometimes more additional arguments), and ...
Gwang-Jin Kim's user avatar
2 votes

Lisp: circular structure printing through user-defined print methods: what are the requirements?

The answer is: yes, but the printer is not required to sweep the whole image, only the objects provided to printing functions. Nothing forbids the Lisp printer from performing multiple passes or any ...
acelent's user avatar
  • 429
1 vote

Scheme's define in Common Lisp

You don't have to use LET when using DEFUN: you can define local variables in the parameter list: (defun foo (a) (let ((b (expt a 3))) (+ a b))) is also (defun foo (a &aux (b (expt a 3))) ...
Rainer Joswig's user avatar
1 vote

Why are Lisp programs a sequence of S-expressions and not a single list?

It would seem logical and natural that program is a list of s-expressions to execute (as it is already implicitly understood just looks like missing explicit list declaration). Only if you think of ...
Telastyn's user avatar
  • 109k
1 vote

How can a compiler be written for a language that allows rewriting code at runtime (such as Lisp macros)?

I cannot understand how it would be possible to write a compiler for a language that allows you to rewrite code at-runtime (and then execute that code). How is this done? Is the compiler itself ...
Eric Lippert's user avatar
  • 46.2k
1 vote

Why is studying a Lisp interpreter in lisp so important?

A Lisp interpreter written in Lisp can be given as a weekly or even overnight homework assignment. Whereas making a from-scratch interpreted language would be more of a semester project. A Lisp ...
Kaz's user avatar
  • 3,622
1 vote

Does this happen in Common Lisp?

That is precisely backwards. The surprising situation is that you have some data like: (the (quick brown (quote jumped) over) the lazy symbol) This data is not code; it's just some symbols. But when ...
Kaz's user avatar
  • 3,622

Only top scored, non community-wiki answers of a minimum length are eligible