Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 17 15:37
    ishehadeh commented #912
  • Jan 16 21:41
    andrewchambers commented #912
  • Jan 16 21:39
    andrewchambers commented #912
  • Jan 16 20:09
    ishehadeh commented #912
  • Jan 16 03:28
    andrewchambers commented #912
  • Jan 16 03:27
    andrewchambers commented #912
  • Jan 16 03:26
    andrewchambers commented #912
  • Jan 16 03:25
    andrewchambers commented #912
  • Jan 16 03:24
    andrewchambers commented #912
  • Jan 16 03:24
    andrewchambers commented #912
  • Jan 15 23:38
    eko234 commented #912
  • Jan 15 22:32
    bakpakin commented #912
  • Jan 15 20:12
    ishehadeh opened #912
  • Jan 14 23:14
    bakpakin closed #889
  • Jan 14 21:15
    sogaiu commented #911
  • Jan 14 18:14
    pyrmont edited #911
  • Jan 14 18:13
    pyrmont opened #911
  • Jan 14 18:06
    pyrmont commented #889
  • Jan 14 15:16
    elimisteve commented #898
  • Jan 14 14:16
    sogaiu commented #898
llmII
@llmii:matrix.org
[m]
but that's an internal, and I cannot guarantee with any certainty what I just said was/is true
llmII
@llmii:matrix.org
[m]
@Grazfather: the fix you submitted a pull request for? did that fix it for you?
1 reply
sogaiu:matrix.org @sogaiu:matrix.org bets on performance
sogaiu
@sogaiu:matrix.org
[m]
possibly of interest is partial's implementation in clojure
saikyun
@saikyun
I think the discussion wrt haskell arity (map1-8) vs janet is one of the areas where dynamic languages shine :)
saikyun
@saikyun
@bakpakin it seems to me that (dyn :current-file) is absolute path on linux/mac, but relative on windows. is this intentional?
or... now I'm confused.
never mind, I think it had to do with how I ran the files
so if I do dofile with an absolute path, I get the absolute path :) that makes sense
iiuc jpm build runs with relative path on windows, and full path on linux/macos
saikyun
@saikyun
nvm again, it had to do with how I declare :entry in declare-executable. so if that is an absolute path, it affects (dyn :current-file)
ahhh, now I get it. iiuc (dyn :current-file) seems to always use / as the separator, even on windows
Jeanne-Kamikaze
@jeannekamikaze
Hi. Do we have anybody from the Joy framework here? I'd like to use its html templating without importing the whole package, but I can't exactly find which part of the code is responsible for that. The documentation mentions that they use hiccup, but that seems to be a Clojure project.
llmII
@llmii:matrix.org
[m]
@jeannekamikaze: probably musty (https://github.com/pyrmont/musty)
I'm not from that project, but reading their project.janet, I think that's what it uses for templating, double check though, I could be wrong
Jeanne-Kamikaze
@jeannekamikaze
Ah, that explains why I couldn't find the relevant bit of code. I think that's the one, thanks.
Gijs Stuurman
@thegeez
@jeannekamikaze the hiccup-esq lib in joy is: https://github.com/swlkr/janet-html
Leah Neukirchen
@leahneukirchen
if anyone knows such a thing that generates "properly" indented html, i'm interested
Jeanne-Kamikaze
@jeannekamikaze
@thegeez Thank you.
heyarne
@heyarne:matrix.org
[m]
I just wrote a small CLI tool to send some commands via TCP to my speakers, had a super pleasant experience using janet and Conjure :) https://github.com/heyarne/arylic-uart-tcp-cli
1 reply
andrewchambers
@andrewchambers
nice :)
sogaiu
@sogaiu:matrix.org
[m]
heyarne: i like your usage example :)
heyarne
@heyarne:matrix.org
[m]
thanks :) i actually set out to write it in python, but on a whim I thought "didn't janet basically just let you handle strings as arbitrary buffers of data" and that fit really nicely. plus i get a ~600kb executable for free
1 reply
willfennel
@willfennel:matrix.org
[m]
Wrote my first Janet macro today: a verbose version of if, where you have to explicitly specify the then-case and the else-case. I don't know much about macros yet so if I'm doing something weird let me know!
(defmacro ifte
  ``
  ifte = if-then-else

  Works just like `if`, but you have to supply `:then` and `:else` keywords for
  extra verboseness. This can be helpful when the then-expression of
  else-expression is huge and it becomes hard to keep track of things. In
  general, you should probably consider creating variables to mitigate that
  problem, but sometimes you're better off using `ifte`.

  Usage: (ifte true :then true :else false)
  ``
  [if-condition then-keyword then-expression else-keyword else-expression]
  (with-syms [$if-condition
              $then-keyword
              $then-expression
              $else-keyword
              $else-expression]
    ~(let [,$if-condition ,if-condition
           ,$then-keyword ,then-keyword
           ,$then-expression (when ,$if-condition ,then-expression)
           ,$else-keyword ,else-keyword
           ,$else-expression (unless ,$if-condition ,else-expression)]
       (assert
         (= :then ,$then-keyword)
         "The second argument of `ifte` should always be the :then keyword.")
       (assert
         (= :else ,$else-keyword)
         "The fourth argument of `ifte` should always be the :else keyword.")
       (if ,$if-condition
           ,$then-expression
           ,$else-expression))))
1 reply
willfennel
@willfennel:matrix.org
[m]
Ah thanks! I'll implement that
Zach Smith (subsetpark)
@subsetpark:matrix.org
[m]
(Not a macro thing, but you could also probably make it shorter using match, with literal keywords in the appropriate positions in the matching pattern)
willfennel
@willfennel:matrix.org
[m]
Is this what you meant?
(defmacro ifte
  [if-condition then-keyword then-expression else-keyword else-expression]
  (assert
    (= :then then-keyword)
    "The second argument of `ifte` should always be the :then keyword.")
  (assert
    (= :else else-keyword)
    "The fourth argument of `ifte` should always be the :else keyword.")
  (with-syms [$if-condition
              $then-expression
              $else-expression]
    ~(let [,$if-condition ,if-condition
           ,$then-expression (when ,$if-condition ,then-expression)
           ,$else-expression (unless ,$if-condition ,else-expression)]
       (if ,$if-condition
           ,$then-expression
           ,$else-expression))))
Hmm I guess the if-condition doesn't have to have a generated symbol either, as it will always be evaluated?
willfennel
@willfennel:matrix.org
[m]
So I guess this is better:
(defmacro ifte
  [if-condition then-keyword then-expression else-keyword else-expression]
  (assert
    (= :then then-keyword)
    "The second argument of `ifte` should always be the :then keyword.")
  (assert
    (= :else else-keyword)
    "The fourth argument of `ifte` should always be the :else keyword.")
  (with-syms [$then-expression
              $else-expression]
    ~(let [,$then-expression (when   ,if-condition ,then-expression)
           ,$else-expression (unless ,if-condition ,else-expression)]
       (if ,if-condition
           ,$then-expression
           ,$else-expression))))
Zach Smith (subsetpark)
@subsetpark:matrix.org
[m]
Like this:
repl:1:> (defmacro ifte
repl:2:(> ""
repl:3:(> [& args]
repl:4:(> (match args
repl:5:((>  @[if-cond :then then-exp :else else-exp] ~(if ,if-cond ,then-exp ,else-exp)
repl:6:((>  (error "Expected (ifte <if> :then <then> :else <else>")))
<function ifte>
repl:7:> (ifte true :then (print "ok") :else (/ 0 0))
ok
nil
repl:8:> (ifte false :then (print "ok") :else (/ 0 0))
-nan
repl:9:> (ifte true (print "ok") :else (/ 0 0))
repl:9:1: compile error: error: (macro) Expected (ifte <if> :then <then> :else <else>
  in ifte [repl] on line 6, column 2
repl:10:>
You don't have to bind to additional symbols, because if is also a macro (or a special form, don't remember). So you can feel free sticking whatever you like in the then and else positions of a normal if form, and they won't be automatically evaluated
1 reply
Just as, when you hand-write an if, those don't get evaluated
repl:10:> (if false (error "oh nooooo!"))
nil
Zach Smith (subsetpark)
@subsetpark:matrix.org
[m]
repl:11:> (ifte true :then (print "ok") :else (error "oh noooo!"))
ok
nil
crocket
@crocket
Isn't matrix.org slow?
Anyway, can I update all jpm packages with one jpm command?
willfennel
@willfennel:matrix.org
[m]
I didn't know about match yet, btw. I like it, but it does make the macro its signature less descriptive in this case. 🤔
willfennel
@willfennel:matrix.org
[m]
Ah, I can change the signature and the match expression, of course:
(defmacro ifte
  [if-cond then-kw then-exp else-kw else-exp]
  (match
    @[if-cond then-kw then-exp else-kw else-exp]
    @[if-cond :then   then-exp :else   else-exp]
    ~(if ,if-cond ,then-exp ,else-exp)
    (error "Expected (ifte <if> :then <then> :else <else>"))
willfennel
@willfennel:matrix.org
[m]
Whoa, I didn't know that would result in compile time errors if the wrong keywords are supplied. That's awesome!
Will stop spamming now. Thanks again, Zach Smith (subsetpark)
andrewchambers
@andrewchambers
@willfennel:matrix.org macros run at compile time
so an error thrown in a macro must be a compile time error
willfennel
@willfennel:matrix.org
[m]
Ah yes, makes sense 👍️
pp
@damnpepe:matrix.org
[m]

bakpakin: the latest Janet is not showing error message only the stacktrace I guess after janet-lang/janet@e8c7380 Repro:

> janet -e '(empty? 1)'
  in empty? [boot.janet] on line 121, column 50
  in _thunk [eval-string] (tailcall) on line 1, column 1
  in eval1 [boot.janet] on line 2333, column 16
  in run-context [boot.janet] on line 2393, column 13
  in eval-string [boot.janet] on line 2432, column 3
  in e-switch [boot.janet] (tailcall) on line 3618, column 12
  in cli-main [boot.janet] on line 3644, column 13

Is it by design? Or is it error on my side?

bakpakin
@bakpakin:matrix.org
[m]
Hmm that is a bug. There were some changes there to handle a missing status line in some cases but I missed a really obvious case.
I will release a 1.19.2 patch today with a fix
pp
@damnpepe:matrix.org
[m]
thank you very much
It is fixed here, thank you
pp
@damnpepe:matrix.org
[m]
speaking of macros, I am playing with these two:
(defmacro vars [& bindings]
  ~(upscope
     ,;(seq [[n v] :in (partition 2 bindings)] (tuple 'var n v))))

(defmacro defs [& bindings]
  ~(upscope
     ,;(seq [[n v] :in (partition 2 bindings)] (tuple 'def n v))))
tionis
@tionis:matrix.org
[m]

How would one increase the value of a field in a 3-dimensional array by one (like the ++ macro does) the janet way?

To give an example I want to increase the 1 to a 2:

@(
  @(
    @(0 0 0) 
    @(0 1 0) 
    @(0 0 0)) 
  @(
    @(0 0 0) 
    @(0 0 0) 
    @(0 0 0))
)
1 reply