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

Pages: 1-4041-

Extending Racket with new languages

Name: Anonymous 2011-06-19 3:27

http://hashcollision.org/brainfudge/

Nicely done tutorial on how Racket can be used to write new languages, with a syntax that significantly differs from S-expressions. Apparently, it's super easy.

Name: Anonymous 2011-06-19 4:03

At least Brainfuck is readable and doesn't require a special editor.

Name: Anonymous 2011-06-19 4:20

>>2
Good troll :)

Name: Anonymous 2011-06-19 4:29

Can LISP do this?  LISP fanatics have said its easy to implement a C interpreter with LISP macros.

Name: Anonymous 2011-06-19 5:08

>>4
Yes. There is a C compiler on the LispM, which is of course better than an interpreter.

It's not to hard to implement special syntaxes for Lisp, you just hook the reader then implement a parser and from there it's all Lisp. If you want other large-scale examples, look at this Python implementation in CL: http://common-lisp.net/project/clpython/

I do have to admit though that it's nice that Racket has its #lang, while in CL you would have to make your own #lang if you wanted a standardized interface for switching readers.

Name: Anonymous 2011-06-19 5:54

>>4
>LISP fanatics have said its easy to implement a C interpreter with LISP macros.
Yes. Just write a parser C/C++.

Most problematic would be handling of 32-bit integers, because Lisp's fixnums are 30-bits and don't overflow.

Name: Anonymous 2011-06-19 6:00

because Lisp's fixnums are 30-bits and don't overflow.
That depends on implementation and even in the same implementation, 32-bit and 64-bit versions will have different fixnum sizes. The standard way of handling it is to just  logand the results with (1- (ash 1 32)), and maybe sprinkle some the declarations and maybe some implementation-specific ones too. Some implementations have efficient MD5/SHA1 implementations which can be examined to see what declarations should be used for efficient compilation (if you don't care about that, then just don't use any and leave it to the compiler).

Name: Anonymous 2011-06-19 6:05

>>7
Efficiency would be the main reason to compile C/C++ into Lisp: to compare compiler quality and use available fast implementation, from inside Lisp. Ideally, C/C++ compiled to Lisp should run as fast as C/C++ compiled by GCC.

Name: Anonymous 2011-06-19 6:07

>>8
C compilers tend to be better at optimizing C, at least on x86.
Compiling C to Lisp made sense on Lisp Machines as the underlying platform was build on Lisp from the ground up (from the CPU and its microcode to the language and OS).

Name: Anonymous 2011-06-19 6:16

>>8
compile C/C++ into Lisp
That's a bad idea -- at least assembly is readable!

Name: Anonymous 2011-06-19 6:20

>>9
C compilers tend to be better at optimizing C, at least on x86.
It depends on hints, compiler has. Lisp System, for example, can gather run-time statistics and optimize hot-spots just-in-time -- sadly an unused opportunity.

>Compiling C to Lisp made sense on Lisp Machines as the underlying platform was build on Lisp from the ground up
It would made sense doing the same to get rid of CFFI dependencies.

Name: Anonymous 2011-06-19 6:22

>>10
It's hard to do code transformation algebra with assembly.

Name: Anonymous 2011-06-19 6:33

>>11
Learn to quote, faggot.

>>12
LLVM bitcode then.

Name: Anonymous 2011-06-19 7:32

>>12
It's hard to do code transformation algebra with LLVM bitcode.

Name: Anonymous 2011-06-19 7:49

>>11
>> Compiling C to Lisp made sense on Lisp Machines as the underlying platform was build on Lisp from the ground up
It would made sense doing the same to get rid of CFFI dependencies.

Yeah, you just take your OS and compile it to Lisp. No CFFI is necessary anymore, problem solved, next!

Name: Anonymous 2011-06-19 8:08

>>6
Most problematic would be handling of 32-bit integers
In Racket, you have the unsafe-fx procedures: limited to fixnums and they overflow. The C standard says nothing on integers being exactly 32 bits, right?

Most problematic would be the parser.

Name: Anonymous 2011-06-19 8:09

>>15
POSIX layer != OS

Name: Anonymous 2011-06-19 8:11

>>16
The C standard says nothing on integers being exactly 32 bits...
but most of C/C++ code assume that typedef unsigned long Uint32; will work. Standard is useless.

Name: Anonymous 2011-06-19 8:16

>>18
Most code breaks on x64 because of those assumptions.
Why let bad programmers be bad?

Name: ADS the new Autism 2011-06-19 8:33


le discusion (yes im offten at reddit and its way better than prog ever was)

Name: Anonymous 2011-06-19 9:27

fucking lisp why does it turn perfectly healthy autists to faggots

Name: Anonymous 2011-06-19 9:43

>>19
You're right, but all C/C++ programmers are genuinely bad.

Name: Anonymous 2011-06-19 9:53

>>18
You are a disgrace. unsigned long is 64-bits on 64-bit platforms with GCC and Intel C++ on Posix/Unix platforms.

You should use the C99/C++11 standard sized-types like uint32_t or uint64_t if you want strong guarantees.

Name: Anonymous 2011-06-19 9:54

>>16
No, but the C standard does say that int32_t will be at least large enough to hold a 32-bit value.

Name: Anonymous 2011-06-19 10:41

>>24
Contracts and integer-in, then.

Compiling C to other languages is pointless, anyway. We only use it because of the fast compilers that systematically miscompile your code (to optimize and make it crash faster), and because OSes only provide C APIs.

Name: Anonymous 2011-06-19 14:44

>>25
We use C/C++ cause of cheap Linux-monkey workforce. Their software is inconsistent and faulty, but it's free and fast as kamikaze's flight.

Name: Anonymous 2011-06-19 15:45

>>26
Implying LISP isn't faster than C.

Name: Anonymous 2011-06-19 15:46

>>27
Implying

Name: Anonymous 2011-06-19 15:48

>>27
>implying you aren't a little cocksucking lithpfag

Name: Anonymous 2011-06-19 15:49

>>26
Welcome to freedom.

Name: Anonymous 2011-06-19 15:55

I'm sure this would have been easier to do in C++, probably in 20 lines, because Bjarne told me C++ was excellent.

Name: Anonymous 2011-06-20 1:49

>>27
C/C++ monkeys are forced to use big static arrays + allocators everywhere, where lazy lispers simply mapcar without type declarations.

Name: Anonymous 2011-06-20 2:24

Wasn't goo.gl written in C++?

Name: Anonymous 2011-06-20 3:20

>>33
Thats why google/youtube error page mentions "A team of highly trained monkeys".

Name: Anonymous 2011-06-20 3:24

No, it's a train of highly teamed monkeys.

Name: Anonymous 2011-06-20 3:54

These are savage, untamed dicks.

Name: Anonymous 2011-06-20 4:22

With garbage, anonymous nicks.

Name: Anonymous 2011-06-20 8:15

>>32
GCs can be faster than manual memory allocation.

Name: Anonymous 2011-06-20 10:16

>>38
Correct C/C++ code allocates all the memory in BSS segment.

Name: Anonymous 2011-06-20 10:18

The only thing that is super easy is your mom.

Name: Anonymous 2011-06-20 14:36

it's a waste of time when you could just be using python in the first place

Name: Anonymous 2011-06-20 16:22

it's a waste of time when you could just glue a desktop pc in your pulse heartbeat monitor

Name: Anonymous 2011-06-20 18:05

>>39
Correct C/C++ code allocates all the memory in BSS segment.

Bullshit you fucking moron. I don't know about C++, but there is nothing in C89, C90, nor C99 that specifically that memory is allocted in the BSS segment. You still suck. Go back to playing with you sister's barbie dolls you mental midget.

Name: Anonymous 2011-06-20 18:16

>>43
#pragma facepalm

Name: Anonymous 2011-06-20 19:16

>>43
It's not in the language standard specifications, but it's in every C/C++ ABI Standards for respective platforms where there is a BSS segment. Go cry some more.

Name: Anonymous 2011-06-20 19:29

>>45
but it's in every C/C++ ABI Standards for respective platforms where there is a BSS segment

Bullshit taco bell boy. I can name three servers here at Kodak where this doesn't hold true.

Name: Anonymous 2011-06-20 19:30

>>46
But the only way you would know something like this if you would have ever actually worked a programming job at a major US firm. Now go read SICP you fucking mental midget.

Name: Anonymous 2011-06-20 19:40

>>46
>implying kodak matters

Name: Anonymous 2011-06-22 6:13

Looks like the author updated the tutorial to address optimization issues!

Name: Anonymous 2011-06-22 9:52

implying
Oh you, get back to /g/, please.

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