Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 06 02:08
    bakpakin closed #1005
  • Aug 04 14:25
    pepe commented #1006
  • Aug 04 13:13
    bakpakin closed #1006
  • Aug 04 13:13
    bakpakin commented #1006
  • Aug 04 13:00
    pepe opened #1006
  • Aug 03 01:16
    ahungry commented #324
  • Aug 03 01:11
    ahungry commented #324
  • Aug 02 19:58

    bakpakin on master

    Fix docstring. (compare)

  • Aug 02 17:34

    bakpakin on master

    Add testcase for issue #1005 (compare)

  • Aug 02 17:23
    bakpakin commented #1005
  • Aug 02 17:19

    bakpakin on master

    Get rid of disabled tracing. #1… (compare)

  • Aug 02 17:17
    bakpakin commented #1005
  • Aug 02 17:14

    bakpakin on master

    Address #1005 - Fix janet_call … (compare)

  • Aug 02 17:04
    paulsnar commented #1005
  • Aug 02 16:56
    bakpakin commented #1005
  • Aug 02 16:50
    bakpakin commented #1005
  • Aug 02 15:19
    bakpakin labeled #1005
  • Aug 02 14:58
    paulsnar commented #1005
  • Aug 02 13:00
    paulsnar commented #1005
  • Aug 02 13:00
    paulsnar commented #1005
bakpakin
@bakpakin:matrix.org
[m]
It seems like you are having issues with early binding
tionis
@tionis:matrix.org
[m]
This was my function that executes the presync hook:
(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))
with the error:
error: cfg.janet:138:11: compile error: unknown symbol pre-sync/pre-sync
that's why I then experimented with something like this:
(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))
bakpakin
@bakpakin:matrix.org
[m]

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))
or better than require, dofile if you want to just pass in a bare path
tionis
@tionis:matrix.org
[m]
Ok, thanks for the explanation, this is quite interesting
I will try that!
And also thanks for janet, it is tons of fun to write my system scripts in it 😄
tionis
@tionis:matrix.org
[m]
Hm, still doesn't work. The environment is still cleaned of my internal functions
bakpakin
@bakpakin:matrix.org
[m]
It should work - what do you mean by "internal" functions?
tionis
@tionis:matrix.org
[m]
I mean functions defined on the top level in the parent environment
bakpakin
@bakpakin:matrix.org
[m]

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))
1 reply
Instead, you would need to separate these into two top level statements:
(import my-mod)
(my-mod/abc 123)
bakpakin
@bakpakin:matrix.org
[m]

This is because Janet use incremental compilation, basically a repl. The first example (using do) has the following flow:

  • Read the form (do (import ...))
  • Compile this form and error because my-mod/abc is undefined.

The second working form has the following flow:

  • Read the form (import my-mod)
  • Compile and execute this form. This will modify the current environment to have my-mod/abc defined.
  • Read the next form (my-mod/abc 123)
  • Compile and execute this form. Since 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.

but the incremental part only happens at the top level. Within a top-level block, everything is compiled and executed together
tionis
@tionis:matrix.org
[m]
(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))))
this is the post-sync hook code
James Muguira
@muguira-james

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
@bakpakin:matrix.org
[m]
Use janet_cstringv("count") to wrap the string. Janet wrap string expects an already memory managed string, allocated by the Janet runtime.
1 reply
Levi R. I. Tan Ong
@levitanong
Given that JPM now requires to be built on the machine, does this mean that for CI jobs, we to download and bootstrap jpm each time? If so, this seems a bit wasteful :O
bakpakin
@bakpakin:matrix.org
[m]
I'm not sure why you would need to, although bootstrapping is quick, you are really just paying for the download time
1 reply
tionis
@tionis:matrix.org
[m]
What would be the janet equivalend of piping to /dev/null with streams?
And what would be the best way to pipe a file into a program executed via os/execute without reading the whole thing into memory?
andrewchambers
@andrewchambers
I think you could literally open /dev/null and pass it as stdout
I'm less sure about streams vs files
but the same probably works
tionis
@tionis:matrix.org
[m]
I see, this wouldn't work across platforms though...
bakpakin
@bakpakin:matrix.org
[m]
Yes, only way to read from /dev/null stuff is with (os/open "/dev/null"). Windows has a special file "NUL" that is the same thing.
But those two should capture any system I know of
StayingAlive1998
@StayingAlive1998

@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... ]

StayingAlive1998
@StayingAlive1998
I think i already have Janet installed. I thought that was like step two for windows... lmao.
bakpakin
@bakpakin:matrix.org
[m]
Alright, sounds good. Yes, the build tools are only needed if you want to build Janet from source on windows or build C/C++ extensions for Janet
For hello world, you just need the .msi
StayingAlive1998
@StayingAlive1998
Alright so i created the hello world program file and it is on my desktop. I typed janet hello.janet in the janet window and got repl:1:1: compile error: unknown symbol janet
repl:1:7: compile error: unknown symbol hello.janet
bakpakin
@bakpakin:matrix.org
[m]
The Janet window is a Janet repl. Try what you did from cmd.exe
Eric Shimizu Karbstein
@GrayJack
What about if you try janet.exe hello.janet? Note that I'm not a windows users, it's just my wild guess
StayingAlive1998
@StayingAlive1998
Success. I am programmer now. Thank you.
StayingAlive1998
@StayingAlive1998
So is the Janet repl a virtual turing/state machine?
andrewchambers
@andrewchambers
The janet virtual machine is equivalent to one I suppose
sogaiu
@sogaiu:matrix.org
[m]
Bryan Maass
@escherize
I'm not sure how to diagnose this error message I get when running sudo jpm deps:
$ sudo jpm deps
From https://github.com/janet-lang/json
 * branch            HEAD       -> FETCH_HEAD
HEAD is now at c4671e8 Use normal, module level import in test file.
compiling json.c to build/json.o...
json.c:23:10: fatal error: 'janet.h' file not found
#include <janet.h>
         ^~~~~~~~~
1 error generated.
error: command failed with non-zero exit code 1
error: build fail
  in pdag [/opt/homebrew/Cellar/janet/1.22.0/lib/janet/jpm/dagbuild.janet] (tailcall) on line 79, column 23
  in <anonymous> [/opt/homebrew/Cellar/janet/1.22.0/lib/janet/jpm/pm.janet] on line 215, column 9
  in <anonymous> [/opt/homebrew/Cellar/janet/1.22.0/lib/janet/jpm/pm.janet] on line 200, column 5
  in bundle-install [/opt/homebrew/Cellar/janet/1.22.0/lib/janet/jpm/pm.janet] on line 198, column 3
  in deps [/opt/homebrew/Cellar/janet/1.22.0/lib/janet/jpm/commands.janet] (tailcall) on line 198, column 7
  in _thunk [/usr/local/bin/jpm] (tailcall) on line -1, column -1
  in cli-main [boot.janet] on line 3759, column 17
bakpakin
@bakpakin:matrix.org
[m]
I think the homebrew packaging needs a look - the latest Janet creates an extra symlink for janet.h but should be the same for previous versions. Janet.h should be installed by the installer
Bryan Maass
@escherize
I'll try building on this machine
thanks @bakpakin:matrix.org
bakpakin
@bakpakin:matrix.org
[m]
Both <janet.h> and <janet/janet.h> should work for includes with jpm
Also use jpm show-paths and look for headerpath
andrewchambers
@andrewchambers
whats the reason for the new symlink?