Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    GrayJack
    @GrayJack
    In the end I had to just generate crude C file and compile from there manually
    Erik Svedäng
    @eriksvedang
    oh, ok... yeah now I see
    GrayJack
    @GrayJack
    image.png
    And it works very well
    Erik Svedäng
    @eriksvedang
    haha, that's a weird project!
    GrayJack
    @GrayJack
    Started as a way to learn to statically link several languages that I use more frequently (Rust, C, Julia)
    Julia can't be called from C, so I did Rust and C
    But I knew more languages that can be called from C, so I started expanding
    Erik Svedäng
    @eriksvedang
    ok :)
    Veit Heller
    @hellerve
    i just found a cool talk on partially typed macros. might be one of those things to investigate in the future.
    Veit Heller
    @hellerve

    how about instead of prefixing all names with unsafe we put them in an Unsafe module, so that we can redefine Array.nth inside Unsafe for instance. elaboration:

    (defmodule Unsafe
      (defmodule Array
         (defn nth [a i]
           ; do the thing
         )
      )
    )
    
    (defn my-fun [a]
       (with Unsafe
           (println* (Array.nth a 0))))

    this makes it explicit in both the call site and the definition, and the with Unsafe block just looks good i think

    Erik Svedäng
    @eriksvedang
    That’s a great idea I think!
    Veit Heller
    @hellerve
    its a breaking change, though, so it’ll need a careful soul to work through :P
    Ghost
    @ghost~5de6cb83d73408ce4fd2f7f8
    hi, total noob question if someone has a moment, i'm trying to sum a list of numbers from file
    (Array.reduce + 0 (Array.copy-map &Int.from-string &(lines &(trim-right &(IO.read-file "input")))))
    but carp does not like me: "I can’t match the types (λ [r3, r3] r3) and (Ref (λ [r1, &r2] r1)) within (Array.reduce + ... )))))."
    i've tried randomly adding and removing &s but not having much luck, heh
    Erik Svedäng
    @eriksvedang
    @h4kr_twitter Sorry for the trouble. You need to add a & before the function you send as the first argument to reduce, so &+ in this case. But then you can't actually use + for reducing, since the reducing function has to have signature (Fn [a &a] a). So a quick lambda like (fn [a b] (+ a @b)) should solve that. Oh, and the third argument to reduce should also be a ref, so the complete oneliner is the following:
    (Array.reduce &(fn [a b] (+ a @b)) 0 &(Array.copy-map &Int.from-string &(lines &(trim-right &(IO.read-file "input")))))
    Scott Graham
    @sgraham
    Ah, makes sense, thanks
    The in-place reduction function I should have realized..
    Scott Graham
    @sgraham
    I'm still a little fuzzy on why all the &s are required down the chain of arrays though. Is it possible to indicate that I want to move the ownership of the returned value of read-file into trim-right and so on?
    Tom Smeding
    @tomsmeding
    trim-right is probably declared as taking a Ref as input argument, so the type system just doesn't allow you to pass a non-Ref to it
    Scott Graham
    @sgraham
    Ah, I see, I looked at trim-right and it doesn't have any annotations in its signature, but it calls Pattern.substitute and that does indeed want the String to be a reference
    Scott Graham
    @sgraham
    I guess that means that the strings and intermediate arrays aren't deleted until after the Array.reduce completes too, right? Where in theory if there were another version of e.g. Array.copy-mapthat took(Array String)rather than (Ref (Array String)) the input could be freed earlier?
    (Obviously doesn't matter in my trivial example, but I'm imagining if the file was very large, etc.)
    Erik Svedäng
    @eriksvedang
    you can take a look at the generated C if you're curious, should be pretty easy to see the calls to delete__<typename> there
    the & are a bit annoying, yes, perhaps some of them can be avoided in the future, using lifetimes. Most of them are probably just necessary though, writing it as a let might make it more digestible in this case
    Scott Graham
    @sgraham
    Was just doing that :) Thanks!
    Nate Upstairs
    @nateupstairs
    hey, @eriksvedang, did you ever figure out a good pattern for overwriting the SDL paths and stuff on windows? right now i get around it by hacking SDL.carp and SDL_image.carp every time I pull, because re-declaring the paths either before or after importing SDL never seems to overwrite your dynamic code and the paths are always broken
    Erik Svedäng
    @eriksvedang
    Humm... no I probably never did actually. I can try to do that next week, shouldn’t really be that hard to get it to work, I hope!
    Nate Upstairs
    @nateupstairs
    what you wrote before seems like it's going to work, logically, i just think there's a bug in there. if i re-set those values, it never overwrites the ones in SDL.carp and SDL_image.carp, although it SEEMS like it's going to, haha :)
    Nate Upstairs
    @nateupstairs
    btw, is anybody else using emacs and have some good plugins to suggest for things like reflowing and doing auto parens? i don't have much of a lisp background and i don't know which things i should be looking for, especially on conjunctions with evil mode. parinfer? lispyville? is there a good way of selecting a blob and re-flowing indentation?
    Erik Svedäng
    @eriksvedang
    I use smartparens, it’s pretty good I think. My configuration for it is up on my GitHub.
    Nate Upstairs
    @nateupstairs
    sweet, i'll check that out :)
    Tim Dévé
    @TimDeve
    Hi 👋
    I haven't been here in a while. I was wondering if there was a quick way to check for a specific variant of a sumtype in if block or do I have to use a match?
    Veit Heller
    @hellerve
    you have to use a match. i usually include utility functions for that (just? and nothing? for maybe, success? and error? for result)
    Tim Dévé
    @TimDeve
    Thanks. Follow up questions: How can I load a other file from a git module? Should I reexport them in the file called like the git module? And if so how do I do that?
    And a trickier one: Is there anything special happening when allocating a Map? Looking at the compiled C with my novice eyes it just looks like an array of struct representing a pair but when I try running it on my embedded board it explodes.
    Tim Dévé
    @TimDeve
    And only if there are things in it, if it's empty it's fine.
    Veit Heller
    @hellerve
    thats’s interesting! the map is implemented in pure carp, so it definitely shouldnt explode; what is happening exactly?
    and as for the first question: whats the setup? do you want to load a module from git, or do you want to load another file from within a file in that git repo?
    Tim Dévé
    @TimDeve

    It looks like this when it explodes:

    Exception (0):
    epc1=0x40106122 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
    
    >>>stack>>>
    
    ctx: cont
    sp: 3ffffd10 end: 3fffffc0 offset: 01a0
    3ffffeb0:  3fffdad0 3fffff90 3ffeec90 40201631
    3ffffec0:  feefeffe feefeffe feefeffe feefeffe
    3ffffed0:  feefeffe feefeffe feefeffe 3ffef404
    3ffffee0:  00000000 00000000 00000000 00000000
    3ffffef0:  40203685 00000001 3ffef41c 3ffee7b4
    3fffff00:  3fffdad0 3fffff90 00000000 4020172e
    3fffff10:  feefeffe 00000001 3ffee74c 3ffee7b4
    3fffff20:  00000000 00000000 00000000 00000000
    3fffff30:  00012480 0000001c 00000000 3ffee7b4
    3fffff40:  3fffdad0 40201782 00000008 40203c48
    3fffff50:  feefeffe 00000000 00000001 40201790
    3fffff60:  feefeffe feefeffe feefeffe feefeffe
    3fffff70:  feefeffe feefeffe feefeffe feefeffe
    3fffff80:  feefeffe feefeffe feefeffe feefeffe
    3fffff90:  00000001 00000001 3ffef53c feefeffe
    3fffffa0:  feefeffe feefeffe 3ffee784 40202564
    3fffffb0:  feefeffe feefeffe 3ffe8508 40100449
    <<<stack<<<

    I guess someone very familiar with the esp8266 might be able to understand what's happening here but for me having a dump of memory doesn't help much :)

    for the git repo I'm trying to load the file called elements.carp in this repo: https://github.com/TimDeve/hoquet
    Veit Heller
    @hellerve
    oh wow, i have no idea whats going on there
    oh, so youre trying to load a file thats not the entry point from a git repo? thats not really supported as of yet, sorry :(
    i understand how that would be interesting, for sure
    Tim Dévé
    @TimDeve

    Yeah it's weird, the exception 0 is apparently IllegalInstructionCause but looking at the C code there doesn't seem to be any difference between allocating an array or a map and it handles the arrays just fine.

    About the git repo what would be the right way of making the module in the file available? Is there a way to reexport it in the main file? Should I just load it in hoquet.carp and that will make it available to people who load the git repo?

    Veit Heller
    @hellerve
    thats correct :)
    i usually make the main file either be all of the code (if its a small module) or just an importer for everything i want to export
    Veit Heller
    @hellerve
    just as a heads-up to whom it may concern. i just started hosting my own gitea instance (https://veitheller.de/git/) and will be slowly migrating my carpentry packages there. they will be mirrored on github and in the end everything will stay the same i guess, but my primary dev target will be my own instance, especially for my more research-y plans around carp in the coming weeks