Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 04 21:48
    bakpakin closed #996
  • Jul 04 21:48

    bakpakin on master

    Fix #996 - linking command work… (compare)

  • Jul 04 21:26
    bakpakin labeled #996
  • Jul 04 21:24
    bakpakin commented #996
  • Jul 04 21:24
    bakpakin commented #996
  • Jul 04 18:23
    LeviSchuck opened #996
  • Jul 04 16:27
    tionis opened #995
  • Jul 03 17:29

    bakpakin on master

    Allow shorthand for setting tas… (compare)

  • Jul 03 06:00
    pepe commented #991
  • Jul 03 05:34
    pepe commented #993
  • Jul 03 02:11

    bakpakin on master

    Fix function handlers for :out … Merge branch 'master' of github… (compare)

  • Jul 02 17:30

    bakpakin on master

    Use relative path for include/j… Merge pull request #994 from sh… (compare)

  • Jul 02 17:30
    bakpakin closed #994
  • Jul 02 17:29
    bakpakin commented #994
  • Jul 02 15:52
    shassard synchronize #994
  • Jul 02 15:45
    shassard opened #994
  • Jul 02 15:38
    bakpakin closed #788
  • Jul 02 15:38
    bakpakin commented #788
  • Jul 02 14:31

    bakpakin on master

    Add basic test for tabseq Merge pull request #993 from pe… (compare)

  • Jul 02 14:31
    bakpakin closed #993
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?
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