Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 29 03:51

    bakpakin on master

    Add `tabseq` macro. (compare)

  • Jun 29 02:24
    bakpakin closed #248
  • Jun 29 02:23
    bakpakin commented #856
  • Jun 29 02:23
    bakpakin closed #856
  • Jun 29 02:14
    bakpakin commented #984
  • Jun 29 02:02
    bakpakin commented #984
  • Jun 28 15:18
    masukomi commented #984
  • Jun 28 15:17
    masukomi commented #984
  • Jun 25 23:51

    bakpakin on master

    Add support for a dyn :task-id … (compare)

  • Jun 24 05:22
    bakpakin closed #990
  • Jun 24 00:18
    jeannekamikaze opened #990
  • Jun 20 16:28

    bakpakin on v1.23.0

    (compare)

  • Jun 20 16:23

    bakpakin on master

    Github showing old git attribut… (compare)

  • Jun 20 16:09

    bakpakin on master

    Prepare for 1.23.0 release. Remove ssize_t usage. (compare)

  • Jun 20 16:08

    bakpakin on v1.23.0

    (compare)

  • Jun 20 16:06

    bakpakin on v1.23.0

    Prepare for 1.23.0 release. (compare)

  • Jun 20 01:20

    bakpakin on master

    Add support for 0-element array… Fix docstring. (compare)

  • Jun 19 20:07

    bakpakin on master

    Prepare for 1.23.0 release. (compare)

  • Jun 19 19:49
    bakpakin closed #798
  • Jun 19 18:06

    bakpakin on master

    Update changelog to say FFI ini… Fix unset field in JanetFFIType. Fix trailing :pack-all or :pack… (compare)

rrgmitchell
@rrgmitchell

where I have used X instead of an escaped double quote for clarity. This returns

[X]
[]

My question is: where does the second, empty, capture come from? I guess it won't matter, since adding an empty string won't affect my result, but I'd like to know, in case there is something I don't understand about what is going on.

sogaiu
@sogaiu:matrix.org
[m]

@rrgmitchell: iiuc constant already captures: https://github.com/sogaiu/margaret/blob/master/examples/constant.janet#L3-L5

i don't think capture (aka <-) is needed here, so this should work perhaps?

(peg/match ~(sequence "XX" (constant "X")) "XX")
# =>
@["X"]

fwiw, regarding csv handling, i think there have been some attempts.

here are some:

may be they are useful in some way for you.

rrgmitchell
@rrgmitchell
@sogaiu Thanks for the info! I will check these references.
John Gabriele
@uvtc
@bakpakin:matrix.org , re postwalk/prewalk, thank you. I still don't quite get those functions --- in the past, when I've wanted to walk a ds, I've used nested each (or loop) loops, but in my case it's been walking a known ds. Maybe pre and postwalk are more useful generally. Ok, thanks.
E.g.:
(def mat1 [[1 2 3][4 5 6][7 8 9]])
# => ((1 2 3) (4 5 6) (7 8 9))
(postwalk inc mat1) # maybe increment each elem?
# Errors out (can't + a tuple)
sogaiu
@sogaiu:matrix.org
[m]
@uvtc: to increment each number one thing you might do is to check the current "node"'s type -- if it's a number increment, otherwise return as is:
(postwalk (fn [x] (if (number? x) (inc x) x))
          [[1 2 3][4 5 6][7 8 9]])
# =>
((2 3 4) (5 6 7) (8 9 10))
John Gabriele
@uvtc
@sogaiu:matrix.org , thanks!
pp
@damnpepe:matrix.org
[m]
@uvtc: here https://git.sr.ht/~pepe/jakoune/tree/master/item/jakoune/lint.janet#L6 I construct function for walking the Janet source code. Maybe it can give you a better information of how to use it?
pp
@damnpepe:matrix.org
[m]
Also I need to say, that I am usually using [post|pre]walk
John Gabriele
@uvtc
Thanks, @damnpepe:matrix.org . I see that your example is similar to what @sogaiu:matrix.org says above --- the function you pass in to pre-/postwalk is called on every element on its way down through the ds, and so it has to have some smarts about dealing with the different types of object's it is passed.
pp
@damnpepe:matrix.org
[m]
Exactly. Even if I am aware of the zipping and I have my own view (materialized in Eleanor) I am still walking from time to time.
Levi R. I. Tan Ong
@levitanong
Hi all! I'm playing around with PEGs, and I've hit a road block. Is there a way to prevent a capture in a pattern from pushing to the capture stack if its parent "superpattern" doesn't match?
sogaiu
@sogaiu:matrix.org
[m]

not sure i follow.

is it possible drop could be applied to your situation?

do you have some sample code?

Levi R. I. Tan Ong
@levitanong

@sogaiu:matrix.org

Here's the sample code:

(peg/match '{:dd (sequence :d :d)
             :sep (set "/-")
             :date (sequence :dd :sep :dd)
             :wsep (some (set " \t"))
             :entry (group (sequence (capture :date) :wsep (capture :date)))
             :main (some (thru :entry))}
            "1800-10-818-9-818     16/12            17/12            19/12            20/12                               11/01            12/01"
            )

#returns
@["00-10" "10-81" @["16/12" "17/12"] @["19/12" "20/12"] @["11/01" "12/01"]]

I would like to remove "00-10" and "10-81" from the output.

I had thought about drop, but I didn't know how to use it in this situation. :(

bakpakin
@bakpakin:matrix.org
[m]
You should be able to use lookahead to match multiple patterns over the same text
You could use that to make sure some text matches multiple patterns, or one pattern and not another.
bakpakin
@bakpakin:matrix.org
[m]
Hmm, I need to take a look your pattern looks like it shouldn't capture those first captures to me
bakpakin
@bakpakin:matrix.org
[m]
Yup, this is a bug in the "to" and "thru" combinators.
Quick fix is to replaces :main with (some (choice :entry 1)), I will push a fix and file a bug report
Levi R. I. Tan Ong
@levitanong
@bakpakin:matrix.org oh! thanks for the advice :D
So the spirit of quick fix is "if i can't match :entry, i'll just move forward by 1" and the some lets me continue "if i can't match... etc..." repeatedly until the end of input?
Levi R. I. Tan Ong
@levitanong
Can confirm the workaround works for me :D
bakpakin
@bakpakin:matrix.org
[m]
Yup, exactly.
Levi R. I. Tan Ong
@levitanong
To cement my understanding: If i don't have thru or (choice % 1) I get nil because they don't immediately match the pattern and the engine gives up. Is this correct?
tionis
@tionis:matrix.org
[m]
I'm a bit confused by the documentation, how do I use run-context correctly when i want to execute some code that has access to my current environment/functions?
andrewchambers
@andrewchambers
@tionis:matrix.org can you pass in the output of curenv ?
tionis
@tionis:matrix.org
[m]
I'm more generally confused on how to feed it the string to parse, do i have to wrap it with function that returns chunks or how is this meant to be used?
andrewchambers
@andrewchambers
hmm - don't know off hand and don't have access to my stuff - But a good place to look is just to read boot.janet if you didn't already
tionis
@tionis:matrix.org
[m]
Nevermind, I just read the implementation of eval-string, this helped a bit
I think my mistake is somewhere else
andrewchambers
@andrewchambers
all good
tionis
@tionis:matrix.org
[m]
Is this a bug or intended?
Ok. I found the problem, when compiling the janet script into an executable the code parsed in the runtime doesn't have access to the parent environment functions.
Wait scratch that

Why does this work:

(defn test-func []
  (print "Hello there!"))

(defn test []
  (def test-func-2 (eval-string "(fn [] (test-func))" ))
  (test-func-2))

(test)

but this doesn't?:

(defn test-func []
  (print "Hello there!"))

(defn test []
  (def test-func-2 (eval-string "(fn [] (test-func))" ))
  (test-func-2))

(defn main [& args]
  (test))
1 reply
bakpakin
@bakpakin:matrix.org
[m]
When running as a script (a main function), the environment is basically emptied of various defs and such. This is so that it behaves as if it were compiled.
tionis
@tionis:matrix.org
[m]
Ah I see
bakpakin
@bakpakin:matrix.org
[m]
Janet, unlike many lisps, does not late bind defs and defns by default
tionis
@tionis:matrix.org
[m]
What does late bind mean?
bakpakin
@bakpakin:matrix.org
[m]
I guess not entirely relevant to this particular example, but essentially the redefining things does not update old references.
in this example, the issue is that there is always a "current environment" that contains all dyanmic bindings, as well as avaiable symbol definitions used by the compiler. This environment will be different in the script with main function to better emulate a compiled program
Try adding (pp (curenv)) before (test) in both cases
tionis
@tionis:matrix.org
[m]
Ah yes, now I see it
Is there a good way then to write a program, compile it and then at runtime load some janet-code and execute it with it having access to some internal functions?
Would I have to construct a new environment?
bakpakin
@bakpakin:matrix.org
[m]
A module?
tionis
@tionis:matrix.org
[m]
Well in my use case I'm writing a dotfile managment tool and want to load pre- and postsync hooks a bit like git but written in janet, importing it with import* like a module gave me problems when compiling it
janet complained about non-existant functions, because they were not loaded yet, as they were intended to be loaded in the runtime
bakpakin
@bakpakin:matrix.org
[m]
What problems did you run into?