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

Pages: 1-

type information in a lisp: DA STANDARD way

Name: Anonymous 2017-01-20 19:12

so I'm making a toy s-expression parser in C which may or may not become a minimal toy lisp interpreter and I'm trying to figure out the best way to do types. I know the classic way is to use the end of the pointer as tag bits but it doesn't really look standard-conforming or portable.

is there a way of doing it that doesn't rely on undefined behavior? the only thing I can think of is making a struct that holds value/pointer and type information but this seems very wasteful.

Name: Anonymous 2017-01-20 19:36

A struct seems much nicer. You could test both and see how you like them. I mean, it's a lot more work to implement both in separate branches, but at least you'd know. FWIW I like the struct idea.

Name: Anonymous 2017-01-20 19:49

>>2
I think this is what I'll end up doing, mostly because I want to make as little assumptions about target architecture as possible. my ultimate goal would be to make an stb-like one-file library which allows people to easily add Lisp-like scripting to C projects, and stb libs are usually more about simplicity/minimalism than raw performance.

Name: Anonymous 2017-01-20 21:01

maybe you could mmap a few different spaces, one for each type. then you can tell what type something is based on which space it's in. It's slower than pointer tagging but it's not wasteful.

Name: Anonymous 2017-01-20 21:06

i would use recursive data trees for optimal performance and simplicity of implementation, be careful about null pointers and off by one errors tho

Name: Anonymous 2017-01-20 22:04

>>4
it's not portable though, mmap is a syscall

Name: Anonymous 2017-01-20 23:07

>>6
No, it's a function.

Name: Anonymous 2017-01-21 2:26

>>7
A function f from X to Y is a subset of the Cartesian product X Γ— Y subject to the following condition: every element of X is the first component of one and only one ordered pair in the subset.

Name: Anonymous 2017-01-21 2:33

//not a function according to >>8
//is a function according to the C Standard
void foo(void) {
puts("HAX MY ANUS!");
}

Name: Anonymous 2017-01-21 9:14

>>6
you have to be an idiot

Name: Anonymous 2017-01-21 11:22

πŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡Έ
I claim these dubz in the name of the United States of America
πŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡ΈπŸ‡ΊπŸ‡Έ

Name: Anonymous 2017-01-21 14:44

>>7,10
how am I an idiot? mmap is a POSIX syscall, not (as far as I know) part of C standard library. there is a sort of equivalent on Windows but it looks like it's only for memory-mapped files, which is not what I need here.

Name: Anonymous 2017-01-21 15:38

>>11
#NOTMYDUBS

Name: Anonymous 2017-01-21 17:05

>>3
This sounds like a good idea, just use a struct and step on it.

Name: Anonymous 2017-01-21 19:59

http://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html
mmap is specified by IEEE, the group that also defines POSIX.

Also, from Wikipedia:
In computing, mmap(2) is a POSIX-compliant Unix system call that maps files or devices into memory.

Name: L. A. Calculus !jYCj6s4P.g 2017-01-21 23:35

>>1

Y NOT JUST KEEP DEM AS STRINGS? DEN U JUST NEED 2 KNO HOW 2 SPLIT PAIRS & INTERPRET DA ATOMS ON A CASE BY CASE BASIS

int splitpair(char *car, char *cdr, char *pair);

char s[] = "(1 2 3)";
char car[32], cdr[sizeof s];

while (splitpair(car, cdr, s)) {
assert(!splitpair(NULL, NULL, car)); /* not a pair */
printf("%d\n", atoi(car));
fprintf(stderr, "%s\n", strcpy(s, cdr));
}

stdout:
1
2
3

stderr:
(2 3)
(3)
()

Name: Anonymous 2017-01-22 13:22

>>12
mmap is a POSIX syscall
Wrong.

Name: Anonymous 2017-01-22 18:56

>>16
so the best way of storing type information is not storing type information? I like the simplicity of this solution but I'm not sure how could I do GC with something like this. also, wouldn't there be a noticeable overhead if every operation needed to infer types?

>>17
I guess you're going to be pedantic and argue that it's not a syscall but a function that is a wrapper around it but it doesn't change the fact that it doesn't work on windows.

Name: Anonymous 2017-01-22 19:16

Have you taken the brown pill yet, mateys?

it's a tough pill to swallow! The brown pill was founded in 1999 by Sir Reginald Brownpill, who presents and narrates the attached video.

Forget red and blue pills, brown pills are the way
of the future.

Video related. Please leave your questions, comments, and concerns below about this radical new paradigm of thinking!

Swallow the brown pill today! Red pills are for fedora fucking wearing faggots, blue pills are for the ignorant masses. Ignore the other le epin /pol/ maymays, this one is the readl deal.

Name: Anonymous 2017-01-22 19:17

Name: Anonymous 2017-01-22 19:53

>>20
Secure Connection Failed

The connection to media.8ch.net was interrupted while the page was loading.

The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
Please contact the website owners to inform them of this problem.

Name: Anonymous 2017-01-22 20:03

Just informing you of these dubs.

Name: L. A. Calculus !jYCj6s4P.g 2017-01-22 21:48

>>18
UR JUST PARSING DA DATA, Y WUD U NEED GC? IF U REPRESENT DA EMPTY LIST AS AN EMPTY STRING, DA REPRESENTATION OF DA car+cdr OF ANY PAIR WILL NEVER B LARGER THAN DA PAIR ITSELF, U JUST NEED 2 ADDITIONAL POINTERS

(1 2 3)\0 BECOMES 1\0(2 3)\0
(2)\0 BECOMES 2\0\0 OR 2\0

IT'S NOT ENOUGH 2 REPRESENT LISP DATA STRUCTURES, BUT IT'S ENOUGH 4 PARSING S-EXPRESSIONS IN C

AS 4 FIGURIN OUT DA TYPES, U CAN DO IT ON A CASE BY CASE BASIS. IF UR ONLY INTERESTED IN INTEGERS & PAIRS, U ONLY NEED 1 OR 2 TESTS, TO DETERMINE IF IT'S AN INTEGER OR A PAIR.

DER'S LESS OVERHEAD BECAUSE IF U HAD ALL DA LISP TYPES BUILT IN BEFOREHAND U'D HAVE TO CHECK IF IT'S A SYMBOL, STRING, CHAR, INTEGER, VECTOR, ETC. AND U MIGHT NOT GIV A FUK ABOUT DA OTHER TYPES N JUST PRINT A MESSAGE TELLIN DA RETOID TO REED DA FUKIN STANDARD IF DEY HAVE IT IN DER DATA.

DA DIFFICULTY WITH DIS APPROACH IS U HAVE TO BUILD SOME INFORMATION INTO splitpair (OR ABSTRACT DAT AWAY/PREPROCESS DA DATA), LIKE HANDLING STRINGS N CHARACTERS DAT CAN HAVE ( OR ) IN DEM. STRINGS & ESCAPE CHARACTERS R FAIRLY COMMON SO I THINK U CAN GET AWAY WITH BUILDIN DAT IN, SO:

p = "(\"()\\\"asd\" . \\(\\ \\\")"

s = "\"()\\\"asd\"\0\\(\\ \\\"\0"
car = &s[0];
cdr = &s[10];

Name: L. A. Calculus !jYCj6s4P.g 2017-01-22 21:58

DER'S A CASE WHERE DA STORAGE AINT LARGE ENOUGH N DAT'S IF U HAVE "((a b c)d e)"

SO DER'S NO SPACE TO INSERT DA NULL CHARACTER BETWEEN ) N d

U CAN WORK AROUND DIS EASILY IF U ALLOCATE STORAGE TWICE DA SIZE OF DA INITIAL S EXPRESSION

FUK U SUSSMAN

Name: Anonymous 2017-01-23 9:01

>>23,24
you're right, I don't need GC or structures just for parsing but
UR JUST PARSING DA DATA, Y WUD U NEED GC?
see >3. basically, the parser is the first part of what is supposed to be a library for lispy DSLs. besides cons cells and integers, I'll probably need floats, strings and symbols.

Name: Anonymous 2017-01-23 12:31

>>18
that is a wrapper around it
Does not need to be.

it doesn't work on windows.
Sure it does. There are implementations of it on top of NT and even the winapi.

>>25
You are just too stupid to make a lisp. Better give up.
In my lisp I did something like what Arthur said. When I parsed the sexpr I kept the symbols as strings and returned a different, "lisp object" structure from functions that process the sexpr structure (like the evaluator).

Name: Anonymous 2017-01-23 12:42

>>26
You are just too stupid to make a lisp. Better give up.
I'll be completely honest: one of the goals here is to become less stupid

Name: Anonymous 2017-01-23 17:53

>>27
You may become less ignorant, but you'll never become less stupid.

Name: Anonymous 2017-01-23 21:35

>>28
HAX MY ANUS

Name: Anonymous 2017-01-24 8:56

The problem with you is that you don't think outside the box, just like most appers.

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