+1
Janet/.envrc
+1
Janet/.envrc
···
1
+
use flake
+14
Janet/chapter2/example.janet
+14
Janet/chapter2/example.janet
···
1
+
(def skadi @{:name "Skadi" :type "German Shepherd"})
2
+
(def odin @{:name "Odin" :type "German Shepherd"})
3
+
4
+
(def people
5
+
[{:name "ian" :dogs [skadi odin]}
6
+
{:name "kelsey" :dogs [skadi odin]}
7
+
{:name "jeffrey" :dogs []}])
8
+
9
+
(pp people)
10
+
11
+
(defn main[&]
12
+
(set (odin :type)
13
+
"Well mostly German Shepherd but he's mixed with some")
14
+
(pp people))
+4
Janet/chapter2/shader-example.janet
+4
Janet/chapter2/shader-example.janet
+13
Janet/chapter3/macro-example.janet
+13
Janet/chapter3/macro-example.janet
+19
Janet/chapter3/meta.janet
+19
Janet/chapter3/meta.janet
···
1
+
(defn sequence [& fs]
2
+
(fn [&]
3
+
(each f fs
4
+
(f))))
5
+
6
+
(defn first-word []
7
+
(prin "hello"))
8
+
9
+
(defn space []
10
+
(prin " "))
11
+
12
+
(defn second-word []
13
+
(prin "world"))
14
+
15
+
(defn newline []
16
+
(print))
17
+
18
+
(def main
19
+
(sequence first-word space second-word newline))
+23
Janet/chapter3/querify.janet
+23
Janet/chapter3/querify.janet
···
1
+
(import sqlite3)
2
+
3
+
(defmacro querify [schema-file]
4
+
~(defn ,(symbol table-name) [conn]
5
+
(sqlite3/eval conn ,(string/format "select * from %s;" table-name)))
6
+
7
+
(def conn (sqlite3/open ":memory:"))
8
+
(sqlite3/eval conn (string (slurp schema-file)))
9
+
(def tables
10
+
(->> (sqlite3/eval conn "select name from sqlite_schema where type = 'table';")
11
+
(map |($ :name))
12
+
(filter |(not (string/has-prefix? "sqlite_" $)))))
13
+
(sqlite3/close conn)
14
+
15
+
~(upscope
16
+
,;(map table-definition tables)))
17
+
18
+
(querify "schema.sql")
19
+
20
+
(defn main [&]
21
+
(def conn (sqlite3/open "db.sqlite"))
22
+
(pp (people conn))
23
+
(pp (grudges conn)))
+10
Janet/chapter3/schema.sql
+10
Janet/chapter3/schema.sql
···
1
+
create table people (id integer primary key, name text not null);
2
+
3
+
create table grudges (
4
+
id integer primary key,
5
+
holder integer not null,
6
+
against integer not null,
7
+
reason text not null,
8
+
foreign key (holder) references people (id),
9
+
foreign key (against) references people (id)
10
+
);
+6
Janet/chapter3/set-x-macro.janet
+6
Janet/chapter3/set-x-macro.janet
+10
Janet/chapter3/set-x-verbose.janet
+10
Janet/chapter3/set-x-verbose.janet
···
1
+
(defmacro set-x [& expressions]
2
+
(print "expanding the set-x macro")
3
+
(printf " here are my arguments: %q" expressions)
4
+
(def result ~(upscope
5
+
,;(mapcat (fn [expression]
6
+
[~(print ,(string/format "about to execute %q" expression))
7
+
expression])
8
+
expressions)))
9
+
(printf " and i'm going to return: %q" result)
10
+
result)
+6
Janet/chapter3/set-x.janet
+6
Janet/chapter3/set-x.janet
+61
Janet/flake.lock
+61
Janet/flake.lock
···
1
+
{
2
+
"nodes": {
3
+
"flake-utils": {
4
+
"inputs": {
5
+
"systems": "systems"
6
+
},
7
+
"locked": {
8
+
"lastModified": 1731533236,
9
+
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
10
+
"owner": "numtide",
11
+
"repo": "flake-utils",
12
+
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
13
+
"type": "github"
14
+
},
15
+
"original": {
16
+
"owner": "numtide",
17
+
"repo": "flake-utils",
18
+
"type": "github"
19
+
}
20
+
},
21
+
"nixpkgs": {
22
+
"locked": {
23
+
"lastModified": 1747790854,
24
+
"narHash": "sha256-8TpwOtr0T016HNlVuDcDNq4q+GMKfLStOSwdabrz+rk=",
25
+
"owner": "NixOS",
26
+
"repo": "nixpkgs",
27
+
"rev": "f0d925b947cca0bbe7f2d25115cbaf021844aba7",
28
+
"type": "github"
29
+
},
30
+
"original": {
31
+
"owner": "NixOS",
32
+
"ref": "nixpkgs-unstable",
33
+
"repo": "nixpkgs",
34
+
"type": "github"
35
+
}
36
+
},
37
+
"root": {
38
+
"inputs": {
39
+
"flake-utils": "flake-utils",
40
+
"nixpkgs": "nixpkgs"
41
+
}
42
+
},
43
+
"systems": {
44
+
"locked": {
45
+
"lastModified": 1681028828,
46
+
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
47
+
"owner": "nix-systems",
48
+
"repo": "default",
49
+
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
50
+
"type": "github"
51
+
},
52
+
"original": {
53
+
"owner": "nix-systems",
54
+
"repo": "default",
55
+
"type": "github"
56
+
}
57
+
}
58
+
},
59
+
"root": "root",
60
+
"version": 7
61
+
}
+26
Janet/flake.nix
+26
Janet/flake.nix
···
1
+
{
2
+
description = "A Nix-flake-based Janet development environment";
3
+
4
+
inputs = {
5
+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6
+
7
+
flake-utils.url = "github:numtide/flake-utils";
8
+
};
9
+
10
+
outputs = { self, nixpkgs, flake-utils }:
11
+
flake-utils.lib.eachDefaultSystem (system:
12
+
let
13
+
inherit (pkgs.lib) optional optionals;
14
+
15
+
pkgs = import nixpkgs { inherit system; };
16
+
in
17
+
{
18
+
devShells.default = pkgs.mkShell {
19
+
buildInputs = with pkgs; [
20
+
janet
21
+
sqlite
22
+
];
23
+
};
24
+
}
25
+
);
26
+
}