Build Your Own Lisp: Learn C and Build Your Own Programming Language by Daniel Holden

Build Your Own Lisp: Learn C and Build Your Own Programming Language by Daniel Holden

Author:Daniel Holden [Holden, Daniel]
Language: eng
Format: epub
Tags: C, LISP, Компиляция и интерпретация
ISBN: 9781501006623
Google: GSALogEACAAJ
Amazon: 1501006622
Goodreads: 24666409
Publisher: CreateSpace Independent Publishing Platform
Published: 2014-10-21T20:00:00+00:00


Builtin Functions

* * *

We can read in Q-Expressions but they are still useless. We need some way to manipulate them.

For this we can define some built-in operators to work on our list type. Choosing a concise set of these is important. If we implement a few fundamental operations then we can use these to define new operations without adding extra C code. There are a few ways to pick these fundamental operators but I've chosen a set that will allow us to do everything we need. They are defined as follows.

list Takes one or more arguments and returns a new Q-Expression containing the arguments

head Takes a Q-Expression and returns a Q-Expression with only of the first element

tail Takes a Q-Expression and returns a Q-Expression with the first element removed

join Takes one or more Q-Expressions and returns a Q-Expression of them conjoined together

eval Takes a Q-Expression and evaluates it as if it were a S-Expression

Like with our mathematical operators we should add these functions as possible valid symbols. Afterward we can go about trying to define their behaviour in a similar way to builtin_op.

mpca_lang(MPCA_LANG_DEFAULT, " \ number : /-?[0-9]+/ ; \ symbol : \"list\" | \"head\" | \"tail\" \ | \"join\" | \"eval\" | '+' | '-' | '*' | '/' ; \ sexpr : '(' <expr>* ')' ; \ qexpr : '{' <expr>* '}' ; \ expr : <number> | <symbol> | <sexpr> | <qexpr> ; \ lispy : /^/ <expr>* /$/ ; \ ", Number, Symbol, Sexpr, Qexpr, Expr, Lispy)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.