Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 03 23:33

    bakpakin on localbindings

    Update symbolmapping code with … (compare)

  • Feb 03 22:26

    bakpakin on localbindings

    initial slotsyms implementation symbolslots now use janet_v vec… symbolslots nil when there are … and 7 more (compare)

  • Feb 03 20:35
    AlecTroemel opened #1068
  • Feb 03 15:46
    AlecTroemel commented #1067
  • Feb 03 15:13
    AlecTroemel opened #1067
  • Feb 03 13:27
    saikyun commented #1066
  • Feb 03 13:24
    saikyun commented #1066
  • Feb 03 13:22
    saikyun commented #1066
  • Feb 03 07:44
    saikyun commented #1066
  • Feb 03 04:03

    bakpakin on master

    Fix null check. (compare)

  • Feb 03 03:12

    bakpakin on master

    Fix issue with environments in … (compare)

  • Feb 03 01:18
    bakpakin commented #1066
  • Feb 03 01:17
    bakpakin commented #1066
  • Feb 03 01:04
    bakpakin commented #1066
  • Feb 03 01:04
    bakpakin commented #1066
  • Feb 02 23:36
    sogaiu commented #1066
  • Feb 02 20:08
    saikyun commented #1066
  • Feb 02 18:01
    bakpakin commented #1066
  • Feb 02 08:51
    sogaiu commented #1066
  • Feb 02 08:47
    sogaiu commented #1066
StayingAlive1998
@StayingAlive1998
Great! The more resources the merrier. I especially like a title you gave in the functions category "Lazy Seqs" haha. Thank you Mr.Gabriel.
John Gabriele
@uvtc
You're welcome. It's still pretty incomplete, but I update it every now and again.
Jeanne-Kamikaze
@jeannekamikaze
Hello guys. What happened to file/popen? Is there an equivalent under a different name now?
Looks like I may need os/spawn.
Jeanne-Kamikaze
@jeannekamikaze

Ok, RTFM.

./CHANGELOG.md:- Remove file/popen. Use os/spawn with the :pipe options instead.

StayingAlive1998
@StayingAlive1998

Ive spent many hours trying to figure this out so i feel comfortable asking. How do i write: if x in array1 ... to replace the messes ive created. Ive thought of having one array with all variations of yes and no and if x is in the 0-4 slot in the array than do so and so else if x is in 5-9 slot do so and so. Ive thought of makeing two tuples and placing them in slot 0 and 1 in an array respectively and if the tuple containing a match to x is in array slot 0 do this else do that.
Ultimately id like: if x in dataset check dataset2 if x in dataset 2 do this if not check if x in dataset3 if x in dataset3 do this if x not in dataset restart

if x in dataset
check dataset2
if true
do this
if x not in dataset
do this #there are only 2 datasets. 1 for yes's and 1 for no's
if x not in dataset
prompt user for input again

although ive been trying to figure this out for a total of about 16 hours i find it interesting...

image.png
StayingAlive1998
@StayingAlive1998
in the real world im trying to write a Do you want to play the game y/n prompt that accepts Y YES Yes yes and y and same for no
bakpakin
@bakpakin:matrix.org
[m]
A few things will help you here - first might be wrapping the part you ask the user a question and get a response into a function, say 'ask-question'. This would be a good chance to learn how to use defn.
That sort of "if ladder" pattern can be done with exactly that, a ladder of ifs.
(if condition-1
  do-thing-a
  (if condition-2
    do-thing-b
    (if condition-3
      ...))))
there is a macro to make this easier though - cond
(cond
  condition-1 do-thing-a
  condition-2 do-thing-b
  condition-3 do-thing-c)
bakpakin
@bakpakin:matrix.org
[m]
Second, the logic you want to do is a good use-case for tables or struct. You can "map" an input string to a boolean value to convert it to - for example, the string "Y" should map to true, so should "yes", but "N" and "no" should map to false.
In the spirit of learning I suppose I should leave the rest for you to figure out

An example of a struct as I mentioned above:

(def mapping-struct
  {"Yes" true
    "y" true
    "No" false
    "n" false
     ... # add more here
    })

There are various improvements to this scheme, such as making input case-insensitive, handling bad inputs by asking again, etc.

StayingAlive1998
@StayingAlive1998
image.png
@bakpakin:matrix.org ballin'
StayingAlive1998
@StayingAlive1998
image.png
1 reply
not ballin'
bakpakin
@bakpakin:matrix.org
[m]
Some small style things - "nil" is not the same as nil, use nil for a number of reasons. Next, you should probably make your question function return the answer rather than set a var.
Next suggestion, make another function ask-yn-question to ask a question, and then return a boolean that would be true if the user answers "Yes", "y", etc. This will let you do things like:
(if (ask-yn-question "Proceed into castle?")
   (print "Onward!")
   (print "Thou art a coward!"))
bakpakin
@bakpakin:matrix.org
[m]
A small hint on making the ask-yn-question:
(defn ask-yn-question
   [question]
   (print question)
   # remove the trailing newline
   (def answer (string/trimr (getline)))
   (def boolean (get y-n-struct answer))
   boolean)
The last expression in a function is what the expression "returns" or evaluates to, so the ask-yn-question evaluates to true or false depending on the input (or nil if the use enters some garbage input)
xoich
@xoich
hello! I get an error with jpm install:
$ export JANET_PATH=$HOME/janet
$ jpm install https://github.com/swlkr/janet-html
error: Permission denied: /usr/lib64/janet/.cache
3 replies
pp
@damnpepe:matrix.org
[m]
Oh sorry, that is true.
I missed the first line.
xoich
@xoich
no problem, janet -v is 1.22.0-meson
pp
@damnpepe:matrix.org
[m]
I never do this, so maybe I can ask sogaiu for a help :-)
sogaiu
@sogaiu:matrix.org
[m]
@xoich: may be something here will be of use: https://github.com/janet-lang/jpm/issues/37#issuecomment-972566298
starting at the text beginning "The following are the steps "
StayingAlive1998
@StayingAlive1998
image.png
StayingAlive1998
@StayingAlive1998
boolean makes more sense than gettable actually...
Jeanne-Kamikaze
@jeannekamikaze

I think I'm having a bit of an issue putting modules and macros together. The simplest form of this problem seems to be:

Define a module X with:

  • A function foo.
  • A macro bar that uses "foo".
  • A function baz that uses "bar".

The symbol "foo" works inside the module, and therefore from baz.

However, if another module Y imports X and uses the macro X/bar, then "foo" becomes an unknown symbol, should be "X/foo" instead. Except that "X/foo" doesn't seem to work inside the X module (macro bar, function baz).

Is there a way to refer to a module from inside the module itself?
bakpakin
@bakpakin:matrix.org
[m]
"Escape" the function in the macro with an unquote: ",". This will pass the function inside the macro as a literal to the compiler and avoid symbol lookup again. For macros within macros the situation is a bit more complicated, but there are work around as well.

(defn my-fn [x] (+ x x))
(defn my-mac [y] ~(,my-fn (,inc ,y)))

(my-mac 1) # evaluates to 4, and avoids hygiene problem

Jeanne-Kamikaze
@jeannekamikaze
Worked great, thank you.
xoich
@xoich
@sogaiu:matrix.org thank you, but I would rather keep the janet binary available on my distribution if possible.
sogaiu
@sogaiu:matrix.org
[m]

@xoich: it could be that using both JANET_PATH and JANET_MODPATH might help for your case.

JANET_PATH has to do with where to look for janet libraries while JANET_MODPATH has to do with where jpm installs libarries to.

iirc, the jpm man page has more details.

bakpakin
@bakpakin:matrix.org
[m]
There is also the --tree option to do this more easily
jpm --tree=$HOME/jpm install spork
The tree command will also set the install path of man pages and executable scripts correctly so you should prefer that
xoich
@xoich
@bakpakin:matrix.org thanks, that worked
xoich
@xoich
is there a shortcut for setting nested values? (set (((t :a) :b) :c) 42) ?
3 replies
xoich
@xoich
hi, are there any bindings for readline/linenoise/bestline?
I think the janet repl has a custom one, is it possible to access it from janet?
andrewchambers
@andrewchambers
there was this one
xoich
@xoich
thanks @andrewchambers I'll make one myself, it seems pretty straightforward to create bindings