Live data from Hacker News

Pocketlang

github.com

11–20 of 63 posts

Re: Pocketlang

#11
post #5

Cute but pkInterpretSource() doesn't have any throttling, like the amount of instructions/nodes to execute before suspending, this would be very useful in games. You could limit NPC's ai to 50 instructions or so so that it doesn't cause rendering lag and the ai script would be run in multiple frames until it finishes.

I guess the fiber/coroutine support would be a better solution to this problem? If this works like I think it should work, the code can decide itself when it is a good time to yield control back to the environment instead of freezing execution in a random location until the next frame. For instance when evaluating NPC AIs it may be important that an NPC isn't left dangling in a random state at the end of a frame, but…

Code cannot decide when to yield because it doesn't know how many NPCs I am running in one frame. Maybe I need 10, maybe 2 longer and 8 just quickly for long running/low complexity jobs. If the limit is reached in the middle of "if" statement, e.g.

    if x 
If "x" and "sin(5)" was evaluated but not "cos(20)" then it should just remember VM state and continue next time. I did this in JS and it worked great for distributing NPC load between frames (https://twitter.com/dusan_halicky/status/1173924435923001344) and it didn't required any understanding of the code (I didn't need to carefully check when I need to stop execution), just VM snapshot and continue next frame.

Re: Pocketlang

#12
post #4
post #2

This is pretty neat. I’ve been tinkering with Lua on ARM, so I’m curious to know how it compares to LuaJIT.

If you like Lua and like Lisp-y languages you might like: https://github.com/bakpakin/Fennel which compiles to Lua.

Using that already ;)

Re: Pocketlang

#13
> The language is written using Wren Language and their wonderful book Crafting Interpreters as a reference.

I had to read this a few times to understand that this isn’t saying that Pocketlang is not written in Wren. I was looking for Wren code in the repo and I was slightly confused.

Very cool project though! I always love to see projects inspired by Crafting Interpreters.

Re: Pocketlang

#14

> The language is written using Wren Language and their wonderful book Crafting Interpreters as a reference. I had to read this a few times to understand that this isn’t saying that Pocketlang is not written in Wren. I was looking for Wren code in the repo and I was slightly confused. Very cool project though! I always love to see projects inspired by Crafting Interpreters.

I was about to post similar because in the git repo it also states:

> Pocketlang is a small (~3000 semicolons) and fast functional language written in C

From what I can tell from the comments, pocketlang re-uses and/or re-implements some functionality from the wren language source code:

    $ grep wren src/*.h src/*.c
    src/pk_compiler.c:  /* String interpolation (reference wren-lang)
    src/pk_utils.h:// Source : https://github.com/wren-lang/wren/blob/main/src/vm/wren_utils.h#L119
    src/pk_utils.h:// Copied from wren-lang.
    src/pk_var.h: * wren (https://wren.io/) an awesome language written by Bob Nystrom the
    src/pk_var.h: *     https://github.com/wren-lang/wren/blob/main/src/vm/wren_value.h
    src/pk_var.h:// usage and it has 2 formated characters (just like wren does).

Re: Pocketlang

#16
post #5

Cute but pkInterpretSource() doesn't have any throttling, like the amount of instructions/nodes to execute before suspending, this would be very useful in games. You could limit NPC's ai to 50 instructions or so so that it doesn't cause rendering lag and the ai script would be run in multiple frames until it finishes.

> You could limit NPC's ai to 50 instructions or so

The problem with this approach is that limiting the number of instructions doesn’t necessarily limit the amount of time taken. Any single VM instruction could be a call into a C function that performs a long-running computation.

If you want to robustly limit the amount of time a script runs for, you have to actually time it.

Re: Pocketlang

#17
Off topic: for those thinking it was a programming language optimized for a phone (like I did) the only one I’ve seen come close to being usable is J (APL derivative). I’ve been able to solve quite a few advent of code challenges this way:

1. App https://apps.apple.com/de/app/j701/id1255235993?l=en (there’s an android version I believe)

2. Copy input from page

3. `+/ ".jgetcb''` to get sum

Re: Pocketlang

#18

> The language is written using Wren Language and their wonderful book Crafting Interpreters as a reference. I had to read this a few times to understand that this isn’t saying that Pocketlang is not written in Wren. I was looking for Wren code in the repo and I was slightly confused. Very cool project though! I always love to see projects inspired by Crafting Interpreters.

Do you usually read the second paragraph first?

Re: Pocketlang

#19
post #2

This is pretty neat. I’ve been tinkering with Lua on ARM, so I’m curious to know how it compares to LuaJIT.

Like regular Lua, Pocketlang uses a bytecode interpreter. AFAIK LuaJIT is still the only small language implementation that provides a JIT compiler and not just an interpreter.

I don’t know why that is - maybe there just isn’t much of a niche for a lightweight JIT compiler.

Re: Pocketlang

#20
post #15

> Pocketlang is a [...] functional language written in C. What features make this a functional language?

Probably just referring to the fact that it is not object oriented. Not "functional" in the sense of pure functional programming.
Post reply on HN