Hint: change the char to a void pointer and the discriminant to an enum. It's still not type safe but you're using C and this is the best you can do.
This way you can construct a s-exp with an ADT of the atoms you want or an object for a more traditional opaque unityped language approach.
Name:
Anonymous2015-03-13 4:53
>>2 You mean struct O { union { Cell *o; void *a; }; enum type t; }; ? You're right of course. It was just quick and easy to make all atoms strings.
My main concern was whether it was reasonable to divide O and Cell like that.
Name:
Anonymous2015-03-13 6:18
>>2 should be read Sexp of 'a sexp list. C's * made me confused.
>>3 You can do it either way. I like single-type definition but you can't make that read well in C.
Name:
Anonymous2015-03-13 8:35
JACKSON 5 GET
Name:
Anonymous2015-03-13 9:09
The divide is alright, you are basically constructing an ADT like >>2-san already noted. It might be worth it to move the type to the front: It's more intuitive and probably slightly more efficient because offsets are smaller. You could also add basic integer types to your union since it takes no extra memory under most memory models and saves you numerous allocations of simple numbers.
Name:
Anonymous2015-03-13 13:34
it shouldn't be lists of sexp, it should be pairs.
Using C for anything is not a sane representation. C does not support even most primitive algebraic types natively, forcing you to employ ridiculous tricks like >>1 did (and like I did one time too many). Whoever uses C on their own volition, when presented with suitable alternatives, is a moron.
Name:
Anonymous2015-03-13 14:47
Lisp uses pairs of pointers, not pairs of cons cells.
This isn't valid C89, but I think it's kosher under later, heretical versions. struct O{ enum type type; union{ struct{ O *car, *cdr; } int i; double f; void *o; } }
>>1 It's 2015, why are you using a language with null pointers?
Name:
Anonymous2015-03-13 17:10
Why LISP compiler are written in C/C++? 1. Implement LISP compiler N in LISP and C. 2. Compile N using #1 lisp compiler resulting in N2 compiler. 3. Compile N in N2 resulting in N3. 4. Compile N in N3 resulting in N4. 5.Repeat until the program binary output is identical to previous iteration. 6.Compile N in C, and benchmark #5 versus it. 7.Report results.
until the program binary output is identical to previous iteration
Would require producing output for all possible programs. Shalom!
Name:
Anonymous2015-03-13 17:50
>>18 Only if it was divergent. And even if it was, it wouldn't require generating all possible programs. It could be cyclic, for example. It's clear that they didn't cover set theory in first grade before you dropped out.
Name:
Anonymous2015-03-13 18:07
>>19 To check that the binary outputs of two consecutive versions of the compiler are the same, you would have to test them on all possible programs. There's nothing cyclic here besides your stupidity.
Name:
Anonymous2015-03-13 18:17
>>20 I meant the compiler compiles the N source to the same binary ONLY one source(N) and one compiler(Nx) at each step
Name:
Anonymous2015-03-13 18:18
>>21 But there may exist inputs for which the binary outputs of N and Nx differ, therefore those compilers may be inequivalent.
Name:
Anonymous2015-03-13 18:25
>>20 And to ensure that there is a successor function for all natural numbers, you have to check to make sure that n+1=n* infinitely many times. And to shoot an arrow it first has to move half way, but before that, it has to move a quarter of the way, so clearly motion is impossible.