It'd be nice to have something cleaner than Common Lisp, and a much smaller image size. If it has decent performance too, I'm sold.
> Create a standalone, statically linked executable from a Janet source file that contains a main function.
and discussion here
> My favorite feature of Janet, though, is something that sounds really dumb when I say it out loud: you can actually distribute Janet programs to other people. You can compile Janet programs into statically-linked native binaries and give them to people who have never even heard of Janet before. And they can run them without having to install any gems or set up any virtual environments or download any runtimes or anything else like that.
They're not super tiny, though. A hello world I just did is about 727K.
When I download the Slack desktop app, I might know it’s running on electron because I’m a programmer. But I didn’t have to download and install nodejs or anything else. As far as I’m concerned it’s a completely self contained application.
The end user needn’t download and install Janet or even know that Janet exists.
That can obviously be done with any interpreted language, but Janet makes it really simple out of the box.
Not every processor architecture uses microcode, so this doesn't hold up.
> The point is you don't need janet-specific external dependencies in the environment
Sure.
> I don't differentiate between this and an inefficient compiler
A compiler is the general term here, but the target is not. Targeting the native architecture for a CPU vs targeting a bytecode VM are quite different and have pretty important implications for performance, portability, memory usage, etc.
> But in order to produce native code, jpm actually:
> 1. Compiles your Janet source code into an “image.”
> 2. Embeds the contents of that image into a .c file that also links in the Janet runtime and interpreter.
> 3. Compiles that .c file using your system’s C compiler.
You should try again.
(add-hook 'janet-ts-mode-hook
#'ajsc-interaction-mode)
(add-hook 'janet-ts-mode-hook
(lambda ()
(local-set-key "\C-c\C-x" 'ajsc)))
(add-hook 'janet-ts-mode-hook
(lambda ()
(local-set-key (kbd "C-x C-e") #'ajsc-send-expression-at-point)))
In the janet itself: (def repl-server
(netrepl/server "127.0.0.1" "9365" (fiber/getenv (fiber/current))))
If you have tight main loop, make sure you have something like: (ev/sleep 0)
To allow the netrepl server to take time.Start janet (usually i do it via jpm)
$ jpm -l janet -d main.janet
Then m-x ajsc and localhost:9365This should be default.
If you dont start it in debug mode, you can't redefine functions as they are running.
I have an example using it for live web stuff here: https://github.com/wmealing/janet-joy-live
https://github.com/Olical/conjure
The LSP for it works reasonably well.
(use-package janet-ts-mode
:ensure t
:defer t
:vc (:url "https://github.com/sogaiu/janet-ts-mode"
:rev :newest))
(use-package ajrepl
:ensure t
:defer t
:vc (:url "https://github.com/sogaiu/ajrepl"
:rev :newest)
:hook (janet-ts-mode . ajrepl-interaction-mode))
Also, a fix for treesit auto to not ask for the grammar every time: (use-package treesit-auto
:pin melpa
:ensure t
:custom
(treesit-auto-install 'prompt)
:config
(add-to-list 'treesit-load-name-override-list
'(janet "libtree-sitter-janet-simple" "tree_sitter_janet_simple"))
(add-to-list 'treesit-language-source-alist
'(janet-simple . ("https://github.com/sogaiu/tree-sitter-janet-simple")))
(treesit-auto-add-to-auto-mode-alist 'all)
(global-treesit-auto-mode))[0]: https://github.com/julienvincent/nvim-paredit
[0]: https://github.com/julienvincent/nvim-paredit
According to [1], "the 3SUM problem asks if a given set of n real numbers contains three elements that sum to zero."
It's not clear to me what problem the Janet code solves but it's clearly not that 3SUM problem.
On the example input of
@[2 4 1 3 8 7 -3 -1 12 -5 -8]
it outputs @[@[6 1 7] @[2 5 10] @[1 2 9] @[4 6 9] @[3 0 9] @[6 2 0]]
For what it's worth, here's some Common Lisp code that does solve the 3SUM problem in O(n^2). (defun 3sum (a)
(let ((h (make-hash-table))
(len (length a)))
(dotimes (i len)
(setf (gethash (aref a i) h) t))
(dotimes (i len)
(dotimes (j i)
(when (gethash (- (+ (aref a i) (aref a j))) h)
(return-from 3sum t))))))
(3sum #(2 4 1 3 8 7 -3 -1 12 -5 -8))
;; => t
[1] https://en.wikipedia.org/wiki/3SUM @[6 1 7] == A[6], A[1], A[7] == -3, 4, -1
@[2 5 10] == == 1, 7, -8 _ 11 11 #:,I. 0=,a+/,+/~ a=: 2 4 1 3 8 7 _3 _1 12 _5 _8
Or the 8 solutions in a 2x12 matrix: 2 12 $, ~. (/:~)"1 ({&a) _ 11 11 #:,I. 0=,a+/,+/~ a=: 2 4 1 3 8 7 _3 _1 12 _5 _8
_3 1 2 _5 2 3 _1 _1 2 _8 4 4
_5 1 4 _3 _1 4 _8 1 7 _5 _3 8For bonus points, compiling to a stand-alone JavaScript wrapped in HTML would be awesome if it could be hosted on a Github page.
Similarly, they were supposed to offer "compile to HTML5", but it never really worked for me.
An opinion that flatly and individually labels every extant thing the same has no signal to it. I'm not sure what to make of your original post other than you're expressing displeasure at the universe for not handing you what you wanted and that you believe that expression should be injected into arbitrary discussion.
Should have phrased it as something along the lines of:
>This would be very interesting to me if it had support for a GUI library, and if it were then possible to compile to a stand-alone application which could be easily distributed.
Obviously I understand most of the time someone wants to make a GUI they are not thinking about something like TIC-80. I agree a more complete GUI library would be nice.
But if nothing else it may be worth mentioning that TIC-80 is a fun and easy way to install and try Janet. Even the Android version comes with Janet and a built-in code editor. Just run "new janet" in the TIC-80 console and then press F1 (on Android TIC-80 by default uses its own virtual keyboard that has all the keys it needs) to open the code editor.
So lets say I want to start my next web project in Janet. I already know Scheme and can probably quite easily just start writing another lisp, assuming it has TCO and I can do things mostly like I would in Scheme, except maybe for having to use funcall (which is annoying, but OK). Does Janet have libraries, that enable web projects? Like a web server and SXML or something like that? Or does it have things like a JSON parser? All these little things one would like to have, to not have to develop the basics first, before getting to the actual project.
And what about data structures? Are there functional data structures available? In GNU Guile I have at least the unmaintained guile-pfds. Hopefully, I will one day understand enough about functional data structures to build more or to maybe even maintain that library. But learning resources are scarce. It is already difficult to find a functional version of an AVL tree! Lots and lots of places merely teach non-persistent, non-functional versions of these data structures, and it is not trivial to translate them, might impact performance in ways that are not necessary, if one had great knowledge about how to make these data structures.
And also reproducibility! With GNU Guile I have what I need on Guix, which is great! With other languages, I might need to rely on older package managing approaches, that do not have reproducibility/determinism as the a high goal on their agenda, or might even lack the ability to create lock files/files with checksums. I don't want to go back to non-reproducible.
I am also eyeing statically typed variants like Carp. Same questions arise. Some seem really great and I would probably enjoy using them a lot. Would be a pity to then discover, that the ecosystem is just not there, and one has to create all the basic tools one needs oneself. Sometimes that can be fun, but it can also be exhausting and one never gets around to ones actual project.
As for DS, only arrays, there are maps, arrays and strings, all mutable or immutable. I don't think there's any intention to ever implement functional data structures, but they could "easily" be a library.
- [0] https://github.com/joy-framework/joy - [1] http://janetdocs.org/
(-> a (fun b c)) (define-syntax ->
(syntax-rules ()
;; first expression is left unchanged
[(-> expr) expr]
;; take from the back, wrap other calls
[(-> expr* ... (op args* ...))
(op args* ... (-> expr* ...))]
;; make parens unnecessary in trivial case of no further arguments
[(-> expr* ... op)
(op (-> expr* ...))]))
Janet already having this ... Reading many good things about Janet in this discussion.Also think of autocompletion for 'var x = new' to 'var x = new ByteArenaFactory()', the way you get from nothing to 'ByteArenaFactory' is the same way you get from nothing to '(fun a b c)'.
I also think there's some familiarity bias to the OO style. I don't find it particularly natural, though that's subjective. I often know what I want to do, and have to find the object that has the method. E.g. I know I want to read a particular header, but is it on Request, or on Request.Headers, or are headers passed in as a separate object? It feels cleaner to do something like `(get-header "SOME-HEADER" ` and have the IDE tell me I need to pass in `(get 'headers request)` or similar.
Scheme if you really enjoy recursion.
Clojure if you need the JVM and/or employment (this is me).
Racket if you drink the DSL kool aid.
Fennel (same author as Janet) for Lispy Lua.
Janet for Lispy C.
Scheme was written for educational purposes. It's very minimal, and implementations aren't very compatible for anything outside the spec and the SRFIs (specs for optional functionality). I'd you choose a major implementation like Guile or Chicken however, there are tons of libraries available and it's very usable for small and medium-sized projects. It isn't known for its speed. Choose Scheme if you think like a computer scientist.
I've never used the others enough to comment, although I did enjoy playing around with Clojure since it's a functional language. I'd do more with it if it wasn't tied to Java and JavaScript. I keep telling myself to learn some Racket, but I never have the time.
Personally, I do most of my Lisp work in elisp, since my regular job isn't Lisp-based but I need to mangle text a lot. elisp is from the same tradition as CL so it's pretty similar.
If you're on a GNU system, I found GNU Guile to be exceptional to learn Lisp with. Particularly with following the SICP lectures from MIT (with Hal Ableson and Gerry Sussman). There are lots of great options though!
I lost interest before I got to implementing proper functions, so mine only has variables that can be executed, if you're interested, it's here http://dusted.dk/pages/slispRepl/ but it's a mess, and only interpreted.
bjoli•6mo ago
Why should I switch from my scheme of choice (guile) to Janet?
veqq•6mo ago
Fibers are very interesting, even used for error handling. I've not wrapped my head around PEGs yet.
ggm•6mo ago
exe34•6mo ago
tkrn•6mo ago
To me the homoiconity of Lisp is mainly about code-as-data, the exact nature of the data doesn't matter to me that much as long as it's a first class citizen and enclosed in nicely balanced parenthesis (though sadly here Janet seems to have fallen to the temptations of the curly braces, and thus, is indeed heresy).
gorjusborg•6mo ago
I will not give up my curly braces or square brackets.
throwaway328•6mo ago
Speaking of unconventional lisps, I enjoyed this recently:
https://github.com/vygr/ChrysaLisp/blob/master/docs/lisp/lis...
from Chris Hinsley, author of the (very) cool Chrysalisp operating system. Same author who wrote this in 1995:
http://www.uruk.org/emu/Taos.html
worthless-trash•6mo ago
veqq•6mo ago
worthless-trash•6mo ago
I'd also like to be able to open up each example up on to the playground with the docs above it. (Currently you can just open the example in the playground) no docs right above it.
I did see a json file containing all site data at one point, I did think about using this as a data source for an llm to 'janet' correctly (because at the moment, they do not). This could be displayed/noted more prominently.
None of these are 'must have', just nice to have.
bjoli•6mo ago
I would also make strings immutable, maybe like Guile's cow-strings, maybe blobs-with-cursors.
Definitely just copy Guile's delimited continuations.
I think I would just ignore most of r7rs, since I don't think it improves things for the progrmmer.
bjoli•6mo ago
shawn_w•6mo ago
bjoli•6mo ago
I do use racket, but for scripts I prefer guile. Guile-fibers is a lot neater than the racket parallelism situation, for example. And I can usually find the code responsible for what IAM trying to achieve in the implementation. I never became friends with racket. I remember trying to fix a bug, but I never found what I was looking for.
Getting superficially familiar with the guile codebase takes about an hour.
Then again, I am a classical musician and not a programmer.
shawn_w•6mo ago
I don't see fibers in the guile manual, just heavy weight threads. Is that a third party library? (The lack of a package manager to easily install such things is an issue with most Schemes; only chicken and chibi have anything like Racket's)
bjoli•6mo ago
It does not use mutation, and should produce just as efficient code as the racket loops. It is also extensible (and easily portable to racket!). It is written almost exclusively in syntax-rules.
Guile fibers can be found here: https://codeberg.org/fibers/fibers
girvo•6mo ago
natrys•6mo ago
[1] https://github.com/emacs-mirror/emacs/blob/master/lisp/progm...
bmn__•6mo ago
Actually, the opposite is the case. https://news.ycombinator.com/item?id=32316375
HN readers, don't fall into this trap and waste your time.
girvo•6mo ago
worthless-trash•6mo ago
Its binaries are quite small, could wrap and embed raylib and a few small c libraries with no hassle. This makes distribution much easier.
For my simple 2d game jaylib (raylib) code.
I believe those are pretty standard to have on most OSX machines, the situation is similar for my Linux system.The LLM's really can't deal with janet though, they seem to think its clojure and screw up a lot of things.
johnisgood•6mo ago
asQuirreL•6mo ago
That being said, these days I use Clojure for both (I use babashka to run scripts: https://babashka.org/)
3036e4•6mo ago
I like that it is a small language without dependencies. Have it installed everywhere, including in termux on my phone. Good for scripting.
Used to daydream about a native Clojure and Janet is close enough to that. Does not have everything, but the cost in size and dependencies is so much lower. It is simpler and easier and runs well even on a RPi Zero.
apodik•6mo ago
https://jank-lang.org/
domga•6mo ago
terminalbraid•6mo ago
atemerev•6mo ago
xigoi•6mo ago