Skip to content

Instantly share code, notes, and snippets.

@bakpakin
bakpakin / dagbuild.janet
Created Jun 11, 2021
Parallel, make-like builds - work for adding parallel builds to jpm
View dagbuild.janet
###
### dagbuild.janet
###
### A module for building files / running commands in an order.
### Building blocks for a Make-like build system.
###
#
# DAG Execution
#
@bakpakin
bakpakin / *-by.janet
Last active Mar 4, 2021
group-by, partition-by in Janet
View *-by.janet
(defn group-by
``Group elements of `ind` by a function `f` and put the resutls into a table. The keys of
the table are the distinct return values of `f`, and the values are arrays of all elements `x` of `ind`
such that `(f x)` is equal to the key.``
[f ind]
(def ret @{})
(each x ind
(def y (f x))
(if-let [arr (get ret y)]
@bakpakin
bakpakin / main.janet
Last active Dec 7, 2020
Janet preloading
View main.janet
(import preloader)
# Files that a use may want to load
(def mod1 (require "mod1"))
(def mod2 (require "mod2"))
(defn main [& args]
(preloader/preload "@mod1" mod1)
(preloader/preload "@mod2" mod2)
(dofile "some-user-file.janet"))
View gist:18bef8a954e19879051ee6c5620f27e2
ClJ1bm5pbmcgdGVzdCBzdWl0ZSAzIHRlc3RzLi4uCiAgChtbMzJt4pyUG1swbSAocmFuZ2UgMTAp
OiB0cnVlChtbMzJt4pyUG1swbSAocmFuZ2UgMSAxMCk6IHRydWUKG1szMm3inJQbWzBtIHppcGNv
bGw6IHRydWUKG1szMm3inJQbWzBtIGRlZi06IHRydWUKG1szMm3inJQbWzBtIG1hdGNoIDE6IHRy
dWUKG1szMm3inJQbWzBtIG1hdGNoIDI6IHRydWUKG1szMm3inJQbWzBtIG1hdGNoIDM6IHRydWUK
G1szMm3inJQbWzBtIHJlZ3Jlc3Npb24gMTogdHJ1ZQobWzMybeKclBtbMG0gc2Nhbi1udW1iZXIg
MTogdHJ1ZQobWzMybeKclBtbMG0gc2Nhbi1udW1iZXIgLTE6IHRydWUKG1szMm3inJQbWzBtIHNj
YW4tbnVtYmVyIDEuM2U0OiB0cnVlChtbMzJt4pyUG1swbSBpZi1ub3QgMTogdHJ1ZQobWzMybeKc
lBtbMG0gaWYtbm90IDI6IHRydWUKG1szMm3inJQbWzBtIGlmLW5vdCAzOiB0cnVlChtbMzJt4pyU
G1swbSBpZi1ub3QgNDogdHJ1ZQobWzMybeKclBtbMG0gdW5sZXNzOiB0cnVlChtbMzJt4pyUG1sw
bSBsb29wIDpwYWlyczogdHJ1ZQobWzMybeKclBtbMG0gYmFkIGFyaXR5IDE6IHRydWUKG1szMm3i
View gist:0665d96322f47ac4aa977861e1ef1f5a
Running test suite 3 tests...
✔ (range 10): true
✔ (range 1 10): true
✔ zipcoll: true
✔ def-: true
✔ match 1: true
✔ match 2: true
✔ match 3: true
@bakpakin
bakpakin / client.janet
Created Aug 10, 2020
Broken pipe handling in server
View client.janet
(with [conn (net/connect "127.0.0.1" "8000")]
(printf "Connected to %q!" conn)
(:write conn "Echo...")
(print "Wrote to connection...")
(def res (:read conn 1024))
(print "client done")
(pp res))
@bakpakin
bakpakin / pkgbuild-janet-lang.patch
Created May 16, 2020
Fix pkgbuild skipping static libraries and adds /usr/lib/janet for jpm.
View pkgbuild-janet-lang.patch
diff --git a/PKGBUILD b/PKGBUILD
index 479ef5e..fc24851 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -12,6 +12,7 @@ provides=('janet')
conflicts=('janet-lang-git')
source=("$pkgname-$pkgver.tar.gz::https://github.com/janet-lang/janet/archive/v${pkgver}.tar.gz")
sha256sums=('02724d6074a0d6fa53a548e8bdaaf49999f082e30b277c73444900f739a53062')
+options=('staticlibs')
@bakpakin
bakpakin / utf8.janet
Last active Jan 24, 2021
Use pegs to parse utf8
View utf8.janet
###
### utf8.janet
###
### Pure janet utf8 utils. You should probably just use C.
###
(defn utf8-encode
"Convert a sequence of codepoints to a string."
[x]
(def buf @"")
@bakpakin
bakpakin / fix-include.diff
Created Dec 29, 2019
Fix include in Fennel 0.4.0-dev
View fix-include.diff
diff --git a/fennel.lua b/fennel.lua
index d824823..f32873e 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -2604,7 +2604,7 @@ SPECIALS['include'] = function(ast, scope, parent, opts)
-- splice in source and memoize it
-- so we can include it again without duplication
- local target = gensym(scope)
+ local target = gensym(rootScope, "module")
@bakpakin
bakpakin / linecol.diff
Created Sep 22, 2019
Add line, column to stacktraces
View linecol.diff
diff --git a/src/core/debug.c b/src/core/debug.c
index f433869..2aa238d 100644
--- a/src/core/debug.c
+++ b/src/core/debug.c
@@ -150,8 +150,44 @@ void janet_stacktrace(JanetFiber *fiber, Janet err) {
if (frame->func && frame->pc) {
int32_t off = (int32_t)(frame->pc - def->bytecode);
if (def->sourcemap) {
+ /* Try to get line and column information */
JanetSourceMapping mapping = def->sourcemap[off];