News for hackers. Stuff that matters.
Re:A Programmable Programming Language by shakna on Saturday February 24, 2018 @04:51PM (#16455628)
> I don't buy it.

> A language extension means the syntax wouldn't ever be valid in the base language.

Sure.

     (struct pt ([x : Real] [y : Real]))
That's not valid Racket, but is valid Typed Racket.

A more extreme example:

    int main(int argc, char** argv) { return 0; }
That's C! Oh wait, it's the C #lang [0]...

Which means you can things like:

base.rkt:

    #lang C

    float f( float x1, float x2 ) {
      return x1 / x2;
    }
main.rkt:

    #lang racket

    (require base)

    f(10.2, 1.8)
Those syntaxes aren't compatible, by any stretch. The magic is, Racket gives you access to powerful pre-processing, in the form of some amazing reader macros.

What syntax you use, doesn't really matter, so long as you provide that bridge. They're incompatible syntax, with a custom made parser allowing data to flow both ways.

[0] https://github.com/jeapostrophe/c

Re:A Programmable Programming Language by mcguire on Saturday February 24, 2018 @05:36PM (#16455861)
Shouldn't that second example be

    (f 10.2 1.8)
Re:A Programmable Programming Language by shakna on Saturday February 24, 2018 @07:30PM (#16456395)
Yep. My bad.
Re:A Programmable Programming Language by username223 on Saturday February 24, 2018 @10:32PM (#16456959)
Where does the conversion between C's simple "float" and Scheme's notion of numbers take place? Does the call from "#lang racket" check and convert the arguments before passing to a simple f(), or does a complex f() check and convert its parameters?
Re:A Programmable Programming Language by shakna on Saturday February 24, 2018 @11:06PM (#16457067)
It depends on the implementation, that's for the expander to handle.

In the case of the implementation I listed, it passes it on literally, and compiles it and runs it, and then takes the output and passes it back to Racket. [0]

[0] https://github.com/jeapostrophe/c/blob/master/c/lang/runtime...

Re:A Programmable Programming Language by username223 on Saturday February 24, 2018 @11:47PM (#16457186)
It shells out to the C compiler (hard-coded as "cc") for every function? Oof. That's a pretty limited FFI.

Or maybe I wasn't clear. If Scheme tries to pass a double/bignum/whatever to the C function that expects the float, where is the error caught?

Re:A Programmable Programming Language by shakna on Sunday February 25, 2018 @01:08AM (#16457411)
It's not Scheme that does the passing, just to be clear, it's the library.

In this case, it's just throwing strings around without changing anything. No passing to transform a bignum, no bounds checking. Just tries to run it. (Racket does have a decent FFI [0], but this library is just for classroom example stuff. Not serious work.)

[0] https://docs.racket-lang.org/foreign/index.html