Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 05:47
    pyrmont commented #914
  • 05:28
    harryvederci commented #914
  • 00:16

    bakpakin on master

    Consolidate related tests Support looking up missing symb… Remove :modules dynamic binding and 4 more (compare)

  • 00:16
    bakpakin closed #914
  • 00:16
    bakpakin commented #914
  • Jan 24 07:47
    andrewchambers closed #486
  • Jan 24 07:47
    andrewchambers commented #486
  • Jan 24 02:16
    pyrmont synchronize #914
  • Jan 24 02:08
    pyrmont synchronize #914
  • Jan 23 01:37

    bakpakin on master

    Update CHANGELOG.md (compare)

  • Jan 22 23:11
    sogaiu commented #533
  • Jan 22 17:45
    ishehadeh closed #912
  • Jan 22 16:55
    pyrmont synchronize #914
  • Jan 22 16:31
    pyrmont commented #533
  • Jan 22 16:24
    pyrmont commented #912
  • Jan 21 23:15

    bakpakin on master

    Fix formating on master. Avoid possible infinite loop in… Merge branch 'master' of github… (compare)

  • Jan 21 23:00
    bakpakin commented #914
  • Jan 21 22:45

    bakpakin on master

    Add ppc64 to os/arch Same as #… Merge pull request #915 from Al… (compare)

  • Jan 21 22:45
    bakpakin closed #915
  • Jan 21 22:40
    bakpakin commented #915
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
llmII
@llmii:matrix.org
[m]
(++ (get 1 (get 1 (get 0 3darray)))) possibly
I may have fudged the indexing a bit with the gets but that's sorta it
tionis
@tionis:matrix.org
[m]
this gives me the same error as the get-in macro
```
compile error: expected 2 element tuple for l-value to set
llmII
@llmii:matrix.org
[m]
what's the result of (get 1 (get 1 (get 0 3darray)))?
tionis
@tionis:matrix.org
[m]
nil
llmII
@llmii:matrix.org
[m]
that's why
tionis
@tionis:matrix.org
[m]
(get-in grid [0 0 0]) gives me 0
1 reply
llmII
@llmii:matrix.org
[m]
need to use a get that gets the thing you need gotten
oh hmm, what does (get-in wait, you're using@(instead of@[`?
tionis
@tionis:matrix.org
[m]
yes, they should be the same if I read the docs correctly
llmII
@llmii:matrix.org
[m]
(def arr [0 1 2 3 4])
(put arr 0 (+ 1 (get arr 0)))
# @[1 1 2 3 4]
so...
try put-in
tionis
@tionis:matrix.org
[m]
Oh I overlooked that
Maybe i should look into making my own ++in macro
llmII
@llmii:matrix.org
[m]
I guess it's put and alike for associative datastructures and set for vars
hmmm, no, set works on keyed data structures per the specials doc
but yes, I sorta would have assumed (++ (variant-amount-of-gets-here)) would have worked
tionis
@tionis:matrix.org
[m]
Ok, this does the trick for me:
(defmacro ++in [variable arr] ~(,put-in ,variable ,arr (+ (,get-in ,variable ,arr) 1)))
Zach Smith (subsetpark)
@subsetpark:matrix.org
[m]
I think update-in is probably the best way to do what you want using standard pieces
1 reply
Relevant to the recurring conversation about more powerful version resolution in jpm, this is apparently all the rage: https://nex3.medium.com/pubgrub-2fb6470504f
crocket
@crocket
On gentoo linux, I manage jpm packages as gentoo packages. On other linux distributions, jpm needs to take care of jpm package updates.
jpm doesn't seem to have a command for updating installed jpm packages.
bakpakin
@bakpakin:matrix.org
[m]
Reinstalling a package should update. No easy way to update all at once though besides iterating through the manifest