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

Embedded scripting languages

Name: Anonymous 2014-11-06 8:40

What scripting language would you embed to a program? The performance would not be main issue, since the compiled part of the program would worry about that.

The scripting language would call many functions written in C, C++, or whatever lang that can compile C-like functions (so there needs to be some kind of easy to use FFI).

I thought about options here:
- Lua
- Scheme (tinyscheme or whatever)
- Something else?

Now, what would /prog/ use, and why? ("Read SICP" is not a valid answer here)

Name: Anonymous 2014-11-09 0:09

>>37
A "Javashit clone"? I'm not sure if you actually ever used Lua or Ecmascript before, or just shitposting.

fuck this stupid thread

Name: Anonymous 2014-11-09 8:04

>>38
Actually, being faster than Python means a lot. For instance, Haskell is NOT faster than Python:

http://stackoverflow.com/questions/26765232/haskell-hashtable-performance

Name: Anonymous 2014-11-09 13:09

>>42
And everyone knows Haskell compiler can do more to optimize than C compiler. So Haskell is faster than C. And Lua is faster than Haskell. That means Lua is faster than C. And LuaJIT is event faster than that!

Name: Anonymous 2014-11-09 15:26

>>42
Terrible!

Name: Anonymous 2014-11-09 16:19

>>42
This argument gets posted over and over. It is irrelevant. Nobody uses the hashtable module in Haskell.
Compare stuff that matters: pure Python and pure Haskell text and XML processing, parallel numerical computation, parser performance. Check the goddamn language shootout.

>>44
Terrible[i] dubs.

Name: Anonymous 2014-11-09 17:08

>>45
Since when does the goddamn language shootout have any weight? It's biased by design as it compares unidiomatic, specially contrived programs only. The Haskell there looks like C, damn it. But if you want to write in C, you'll write in C, not in a C-like Haskell, right? The shootout is bullshit.

Compare stuff that matters
Ooh, so we're playing the game called "denial"? Any place where Python beats Haskell with all its static typing and glorious compiler optimizations and Haskell can only match using a wrapper around a C library, is "stuff that doesn't matter"? Haha.

Name: Anonymous 2014-11-09 18:20

>>36
Is there any reason to use regular Lua instead of LuaJIT? They have the same C API, don't they?
LuaJIT supports Lua's C API, but it also has its own FFI that drastically simplifies calling in and out of C (no wrappers, just ffi.cdef "void whatever(void);" and you're off) and allows you to directly use C types with good (JIT compiled) performance.

>>37
Do you really think Javascript is a better programming language than Lua? Don't you have some websites to be apping?

>>40
Are you saying Common Lisp and Scheme are shitty?
Everything but tables and functions compares by value in Lua (strings are interned so that strings with the same contents are only stored once, so a pointer comparison is all that is needed for them). Most of the time, a cheap comparison of pointers for identity of is more useful for complex objects than an expensive deep comparison, so it makes sense to reflect that in the syntax.

Name: Anonymous 2014-11-09 18:33

>>41,47
I never implied Javashit was any better than Lua. Why would I call it Javashit then?

It's a Javashit clone because both are simplistic asspulls with no real thought that use shitty number types, have no real data structures other than half-assed table/dictionaries, have gay syntax and are popular for their ``epic embedding capabilities as a scripting language in rocking web apps''.

My wording must have been wrong. Certainly JS isn't a Lua clone, even thought both share bad features. Calling Lua a JS clone would be like calling C an ALGOL clone, and that sounds indeed retarded. Sorry about that.

Name: Anonymous 2014-11-09 20:48

>>46
I can write a shitty C library that will be outperformed by both python and haskell analogues. So what? Fuck you.

Name: Anonymous 2014-11-09 20:51

>>46
Python outperforms haskell in this particular case because it is comparing C code (CPython to be exact) with pure Haskell:
http://hackage.haskell.org/package/hashmap-1.0.0.2/docs/src/Data-HashMap.html
Oh wait, did you not know that Python is not self-hosting and that the only interpreter you are likely to encounter is written in C and all dict operations are implemented in low-level C with bit-mangling? Holy shit, this must surprise you much!
You may bring up PyPy, which uses platform-specific JIT, but you won't because you're a retard. Fuck off

Name: Anonymous 2014-11-11 3:30

>>46
The authors of the shootout know this very well. That's why they preface their page with this:

Measurement is highly specific -- the time taken for this benchmark task, by this toy program, with this programming language implementation, with these options, on this computer, with these workloads.

Same toy program, same computer, same workload -- but much slower.

Measurement is not prophesy.

Name: Anonymous 2014-11-11 20:41

>>51
Yes, but why do you ignore that and refer to it like it's a representative benchmark suite? Comparison of the fastest among the fastest programs is obviously impractical because 90% of the time when you write in any language, you want to write straightforward and idiomatic programs, not spend a shitload of time optimizing them to reach that language's top speed. And in that 10% of times when all-out optimization is necessary, you'll be better off just using C or C++ or Assembly, so comparing them to a crapload of slower languages is pointless too. So the results of that shootout are pointless in 100% of cases.

Name: Anonymous 2014-11-11 21:04

whatever systemd uses

Name: Anonymous 2014-11-13 19:15

>>53
Well, as of the latest version straight from Lord God Poettering, systemd uses your anus. For pleasure.

Name: Anonymous 2014-11-13 20:32

Name: Anonymous 2014-11-16 17:10

How do you implement an object-oriented programming language without representing the objects as hash tables? For it to be truly OO, you need to be able to add and remove arbitrary object fields during runtime, so the interpreter/runtime/VM needs to use some sort of dynamic representation for them. Or do you just analyze the AST to determine that a certain prototype chain only ever has certain certain fields, and then translate them into memory offsets?

Name: Anonymous 2014-11-16 19:22

>>56
LuaJIT and the various Javascript JITs use runtime information to suss out the "hidden types" common in dynamic language programs. It might look something like this:

1. Our instruments indicate this function is being called a lot. It returns one object, let's see what happens to it.
2. Our instruments indicate that 99.99% of these objects will never have any fields added or removed from them. Looks like a static type.
3. Let's change this function so that it creates a vector with a fixed number of slots, and replace every hash lookup with a direct index into those slots.
4. If a field is added or removed from one of these objects, we back out and convert it into a hash table.
5. If this happens enough times, we should consider recompiling the original function.

IIRC LuaJIT goes a step further, assumes tables will be static by default, and converts any keys visible in the program text into a static lookup from the get go, but you get the idea. Storing everything in hash tables is the simplest, most general way to implement a dynamic language, but you absolutely can optimize it further if you're willing to complicate the implementation and add checks so that the optimization can be reverted if your assumptions turn out to be false.

The downside is increased runtime overhead vs. an ahead of time compiled language. The upside is that a good JIT can take advantage of information that might not be available to a static compiler. i.e. if a function is called thousands of times with one of its inputs never changing, and this input was read from user input and not statically knowable, an AoT compiler would have no choice but to make use of a general function suitable for all inputs, while a JIT could still produce a specialized version of the function for that input. The sweet spot between strictly AoT C and the crazy JITs of Lua and JS would be something like Common Lisp, where the programmer has access to the compiler at runtime and it's their own responsibility to compile specialized versions of functions.

Name: Anonymous 2014-11-16 19:41

>>56
Analyzing the AST only gets you so far because you would have to do it at run time in some cases at least. In a lot of cases it would just take longer to do the analysis.

Interned strings are a good start. As a hash key, they don't need hashing and they will never produce collisions. There is voodoo going on with caching too, which I'm still not clear on.

Name: Anonymous 2014-11-16 19:51

>>57
Splendid, thank you. I was wondering if I'd missed some major interpreter design innovation, but as usual in CS, there's no silver bullet—just a lot of heuristics.

Name: Anonymous 2014-11-16 20:08

>>58
You still need to (mod N) interned strings to fit them in an N-slot hash table, which can absolutely cause collisions, though?

And I don't really get the caching argument against hash tables—if you use open addressing or coalesced hashing, all hash entries are located in a single contiguous block of memory, which should have the exact same hashing characteristics as a vector, unless the wasted space and pseudorandom distribution within it is that significant.

Name: Anonymous 2014-11-16 21:24

>>60
Limiting case: if you intern them you can take the drastic measure of enumerating them and using that for the hash key. At which point, you will need to exceed N different strings to get a collision.

Caching isn't an argument against hash tables. You want to cache things to keep from getting a lookup explosion every time you send a message.

Name: Anonymous 2014-11-23 22:17

>>66
nice dubs mate

Name: Anonymous 2014-11-24 2:16

I like using lua for purely sentimental reasons.

Name: Anonymous 2016-11-16 16:30

>>56
Why can't you just use an array of pointers?

Name: Anonymous 2016-11-16 17:24

>>66
Nice dubs

Name: Anonymous 2016-11-16 17:24

>>65,67
Thank you

Name: Anonymous 2016-11-16 17:25

>>66
Nice dubs

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