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
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
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!