15 ms·
Pocketlang
- rcarmo 5y agoThis is pretty neat. I’ve been tinkering with Lua on ARM, so I’m curious to know how it compares to LuaJIT.
- tsujp 5y agoIf you like Lua and like Lisp-y languages you might like: https://github.com/bakpakin/Fennel https://github.com/bakpakin/Fennel which compiles to Lua.
- rcarmo 5y agoUsing that already ;)
- pansa2 5y agoLike 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.
- thayne 5y agoProbably because a JIT conflicts with the goal of most embedded languages to be small and simple. LuaJIT does manage to be relatively small, but it (meaning the implementation) certainly isn't simple.
- tsujp 5y agoThe language also has a website homepage too: https://thakeenathees.github.io/pocketlang/ https://thakeenathees.github.io/pocketlang/
- dvh 5y agoCute 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.
- flohofwoe 5y agoI 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 either has finished evaluating, or hasn't started yet. https://thakeenathees.github.io/pocketlang/language-api-fibers.html https://thakeenathees.github.io/pocketlang/language-api-fibe...
- dvh 5y agoCode 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 < sin(5) + cos(20) then y = 5; 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 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.
- skybrian 5y agoSince it’s a small language that already supports yielding for I/O, it shouldn’t be too hard to automatically insert an instruction into all loops to check if they need to pause. You could write it manually to prototype. (Or at least I assume it works that way based on studying Wren.)
- mirthless 5y agoWhat about generic algorithms like filter/map. Is it python style like map(fn, filter(...))?
- jorams 5y agoLooks like it supports higher order functions, so you could just implement those yourself.
- garethrowlands 5y agoIsn't python style more about its built-in comprehensions and much less about generic functions? [fn x for x in ... if ...] I know there's a `map` in, say, `multiprocessing.Pool`, but using that doesn't feel as natural as a comprehension in python or `map` in, say, Haskell or Kotlin.
- douglas5962 5y agoThanks for the information keep sharing such informative post keep suggesting such post. https://www.mygiftcardsite.win/ https://www.mygiftcardsite.win/
- fsloth 5y agoThis looks nice! Is there a sample how to implement your own module in C and bind that to the scripting language? [Edit]: To answer myself the API seems really clean and neat, it looks like the patterns used to implement the standard modules can be used as is - e.g. to implement a third party native module, a good pattern to start from is to observe how _fileOpen is implemented in cli/modules.c and added to module using pkModuleAddFunction
- __ryan__ 5y ago> 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.
- veganjay 5y agoI 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).
- leephillips 5y agoDo you usually read the second paragraph first?
- dang 5y agoPlease don't be a jerk in HN comments. https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- EllieEffingMae 5y agoAs do I! Crafting interpreters is definitely one of the coolest programming books I've ever read. I used it as a blueprint for busing more than one parser in my time :D
- sicromoft 5y ago> I had to read this a few times to understand that this isn’t saying that Pocketlang is not written in Wren I had to read that a few times to understand what I think is an unintentional double negative on your part.
- pansa2 5y ago> Pocketlang is a [...] functional language written in C. What features make this a functional language?
- ibraheemdev 5y agoProbably just referring to the fact that it is not object oriented. Not "functional" in the sense of pure functional programming.
- rottc0dd 5y agoI think it is not a purely functional language, but supports functions as first class citizens. > func(x) return x*x end # Lambda/literal functions. [1] [1] - https://thakeenathees.github.io/pocketlang/getting-started-learn-in-15-minutes.html https://thakeenathees.github.io/pocketlang/getting-started-l...
- mumblemumble 5y agoThat's always a fun subject for a late night argument at the pub. When I was in school (1990s), simply having first-class procedures was good enough for most people to consider a language functional. I'd assume that's roughly the definition being used here. But you go back to 20 years before that, and it wasn't totally unheard of to see higher-order functions in procedural languages (such as Algol 68) and object-oriented languages (such as Smalltalk). And you fast forward 20 years, and about the only language without some form of first-class procedures that's still allowed to exist seems to be C. And in the middle there's always been Python. You could go all purist and say that, since John Backus coined the term, we should stick with his definition. In that case lisps are definitely out (he explicitly said so in his paper), and it's possible that the only genuine examples are Miranda, Haskell and friends, because even allowing mutation or an imperative style will disqualify you. But I'm not sure everyone really wants to snub Robin Milner like that. It's almost like it's an ill-defined term with fuzzy boundaries that means whatever the person currently using it wants to tell you they meant by it, and trying to be pedantic about it is mostly just a good way to have a frustrating conversation. Kind of like just about every adjective that can be used to describe programming languages.
- pitr 5y agoOff 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 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
- alanbernstein 5y agoI've just barely begun learning about the APL languages, but I have this tab open that you might be interested in: https://wjmn.github.io/posts/j-can-look-like-apl/ https://wjmn.github.io/posts/j-can-look-like-apl/
- ModernMech 5y agoI love all new pl projects posted to hn, it’s the main reason I come here. This one seems cool and I love the logo especially. My suggestion to the author is to think more on the selling points of the lang. is it the intention of this language is remain small and fast, or is it just a temporary property of the language because it is so new? Most languages start out as fast as C on toy problems, and then slow down as programs become larger as the language becomes more capable. Often it’s the case then you implement the cool features you want your language to have, it’s several orders of magnitude slower than when you started. That’s why so much time is spent on compiler optimizations.
- meneoune 5y agoNice language, but unless I'm mistaken, it's not a functional language but an imperative one.
- throwaway894345 5y agoI love these little embedded languages, but I really want one that supports type annotations. I'm specifically want something that can generate large configuration structures (e.g., Kubernetes YAMLs, CloudFormation YAMLs, Terraform HCLs, etc) and I want some static typing because the iteration loops can be quite long (minutes) which is too long to test every branch and writing and maintaining unit tests to catch type errors is a huge waste of time.
- aarghh 5y agoIt sounds like CUE - https://cuelang.org/docs/about/ https://cuelang.org/docs/about/ may be useful to you.
- throwaway894345 5y agoI've tried Cue, it gives you a type system for static JSON, but the support for functions seems either absent or very, very convoluted. I want to expose this configuration language as an interface to my tools, so the configuration language needs to be somewhat familiar (no need to reinvent functions poorly).
- WmyEE0UsWAwC2i 5y agoSounds like https://dhall-lang.org/ https://dhall-lang.org/
- throwaway894345 5y agoIt's close. I also want something that is going to be syntactically familiar to humble programmers (my target users, myself, etc); Dhall's syntax is clearly Haskell-adjacent which is an obstacle for many of us. I'll probably just roll my own using a Rust-like syntax.
- creata 5y agoIf you don't mind, what is it about the syntax of Dhall that you find hard? In my experience, Haskell's syntax is much simpler than the syntax of any of the popular languages. The "hard" parts of Haskell come with all the abstractions people make (esp. how it encodes side effects), the laziness, and the language extensions. Dhall has none of those.
- prionassembly 5y agoStuff like this is so cool. I have this desire to create a (maybe domain-specific / not Turing) programming language. I have some use cases involving constraint satisfaction but basically it's a rock'n roll dream kind of thing for me.
- hvis 5y agoRuby-like language with imports inspired by Python, what's not to like.
- garethrowlands 5y agoIf I was to design a language, I wouldn't put an implementation of factorial that blows up on its home page!
- jokoon 5y agoHow well can it be called from C++?