bakpakin on master
Add `tabseq` macro. (compare)
bakpakin on master
Add support for a dyn :task-id … (compare)
bakpakin on v1.23.0
bakpakin on master
Github showing old git attribut… (compare)
bakpakin on master
Prepare for 1.23.0 release. Remove ssize_t usage. (compare)
bakpakin on v1.23.0
bakpakin on v1.23.0
Prepare for 1.23.0 release. (compare)
bakpakin on master
Add support for 0-element array… Fix docstring. (compare)
bakpakin on master
Prepare for 1.23.0 release. (compare)
bakpakin on master
Update changelog to say FFI ini… Fix unset field in JanetFFIType. Fix trailing :pack-all or :pack… (compare)
(pp (curenv))
before (test)
in both cases
(defn execute_pre_sync_hook []
(def path_no_extension (string (get_cfg_dir) "/hooks/pre-sync"))
(if (file_exists? (string path_no_extension ".janet"))
(do (print "Executing pre-sync-hook...")
(import* path_no_extension)
(pre-sync/pre-sync))
true))
error: cfg.janet:138:11: compile error: unknown symbol pre-sync/pre-sync
(defn execute_pre_sync_hook []
(def path (string (get_cfg_dir) "/hooks/pre-sync.janet"))
(if (file_exists? path)
(do (print "Executing pre-sync-hook...")
(def pre-sync (eval-string (slurp path)))
(pre-sync))
true))
You modify the environment in the middle of a compiled block - the block is compiled before *import
is run, because compilation always comes before evaluation. No amount of hacks will fix that. As I said, Janet is (almost) always early bound.
eval-string is not the right solution to your problem though, I can tell you that. Could you not do something like:
(defn load-hooks
"load pre and post hooks"
[module-path]
(def module (require module-path))
(def pre-sync (get-in module ['pre-sync :value]))
(pre-sync))
require
, dofile
if you want to just pass in a bare path
They do work, I just tested locally. I think the issue is you are making use of things like eval
and eval-string
inside your "hooks" file. These are inherently dependent on the context they are run in - you would have the same issues in any programming language. Using "require" or "dofile" does not just bring all of the bindings from the given path into the current environment, it returns a fully encapsulated module table. Even *import will auto-prefix bindings before bringing them into the current environment table.
Also, the effect of import or *import has no effect until the top level block is executed. You cannot do:
(do
(import my-mod)
(my-mod/abc 123))
(import my-mod)
(my-mod/abc 123)
This is because Janet use incremental compilation, basically a repl. The first example (using do) has the following flow:
(do (import ...))
my-mod/abc
is undefined.The second working form has the following flow:
(import my-mod)
my-mod/abc
defined.(my-mod/abc 123)
my-mod/abc
was defined in the previous form, this evaluates without compilation error.This incremental compilation is pretty common to Lisps and is not the stringly typed dynamism that is from a language like TCL.
(defn post-sync []
(match ((cfg "config" "node.name") :text)
"citadel" (do (os/execute ["vdirsyncer" "sync"] :p)
(os/execute ["wiki" "calendar_commit"] :p)
(os/execute ["wiki" "contacts_commit" "--no_pull"] :p))))
I am working c++ (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1), trying to add a key to a janet table.
I get the table with: JanetTable *tt = janet_table(0); .
I try to add an entry with: janet_table_put(tt, janet_wrap_string("count"), janet_wrap_number(10)); .
The key shows up as "" when I print the table in the repl?
why?
thank you in advance!
@bakpakin:matrix.org It is not a problem with Janet. I figured out the problem. The Documentation should include a note to Check-Mark the C++ Build tools when installing the VS Build Tools. Now when i type cl.exe it gives me this: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools>cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27048 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]