Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

sexp

Name: Anonymous 2015-03-13 3:34

Is this a sane representation for s-expressions?

struct O
{
union {
Cell *o;
char *a;
};
int type;
};

struct Cell
{
O car, cdr;
};

Name: Anonymous 2015-03-13 4:32

>>1
No.

type 'a sexp = Atom of 'a | Sexp of 'a sexp

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: Anonymous 2015-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: Anonymous 2015-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: Anonymous 2015-03-13 8:35

JACKSON 5 GET

Name: Anonymous 2015-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: Anonymous 2015-03-13 13:34

it shouldn't be lists of sexp, it should be pairs.

LET ME POSt YOU FUCKING SHITBAG

Name: Anonymous 2015-03-13 14:22

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: Anonymous 2015-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;
}
}

Name: Anonymous 2015-03-13 14:48

>>9
this is good

Name: Anonymous 2015-03-13 14:55

struct O{
enum type type;
union{
O *o[2];
char *a;
int i;
/* etc */
}
}

Name: Anonymous 2015-03-13 15:45

>>11
O *o[2];
2
Is that a reference to the dubs you got?

Name: Anonymous 2015-03-13 16:04

>>12

It's a reference to your double sixes!

Name: Anonymous 2015-03-13 16:52

>>1
It's 2015, why are you using a language with null pointers?

Name: Anonymous 2015-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.

Name: Anonymous 2015-03-13 17:16

>>15
Post needs more Rust.

Name: Anonymous 2015-03-13 17:17

>>16
go away shill

Name: Anonymous 2015-03-13 17:32

>>15
until the program binary output is identical to previous iteration

Would require producing output for all possible programs. Shalom!

Name: Anonymous 2015-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: Anonymous 2015-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: Anonymous 2015-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: Anonymous 2015-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: Anonymous 2015-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.

Name: Anonymous 2015-03-13 18:28

>>23
No. No.

Name: Anonymous 2015-03-13 18:48

>>18
>>19
>>20
>>21
>>22
>>23
>>24
lol you guys are dumb

Name: Anonymous 2015-03-13 18:49

>>25
lol you quotes are dumb

Name: Anonymous 2015-03-13 19:07

>>25
The only one dumb here is you, since you have no thoughts to post.

Name: Anonymous 2015-03-13 20:46

>>22
those compilers may be inequivalent
Unlike your digits. Nice dubs.

Name: Anonymous 2015-03-13 23:35

>>1
int[2]

Name: Anonymous 2015-03-13 23:37

>>29
void *[2], even

Name: Anonymous 2015-03-14 3:41

[m]sexp[spoiler]enis[m][/spoiler]

Name: Anonymous 2015-03-14 10:42

>>31
BBCODE FAIL

Name: Anonymous 2015-03-14 13:21

struct O {
char* check, em;
int dubs;
};

Name: Anonymous 2015-03-14 19:15

>>33

(cons 3 3)
-> (3 . 3)

Name: Anonymous 2015-03-15 10:47

>>16
If that post rusts anymore it will collapse.

Don't change these.
Name: Email:
Entire Thread Thread List