Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Erik Svedäng
    @eriksvedang:matrix.org
    [m]
    Sounds reasonable to add in core i think. One problem is that it’s maybe not available on Windows? Perhaps start it as an external library and we can add it in at some point?
    Tim Dévé
    @timdeve:matrix.org
    [m]
    I really need to read some of the docs more carefully, I've been thinking forever that we need an if-else but that's just what cond is...
    I've been chaining ifs like an idiot...
    Veit Heller
    @hellerve
    cond or case are very helpful here
    Scott Olsen
    @scolsen

    Sounds reasonable to add in core i think. One problem is that it’s maybe not available on Windows? Perhaps start it as an external library and we can add it in at some point?

    Sounds good!

    Tim Dévé
    @timdeve:matrix.org
    [m]
    Are you looking into using Carp for "scripting"?
    Scott Olsen
    @scolsen

    Yeah kind of! What sparked this was I was investigating sdiff, which is a nice tool for interactively applying hunks from diffs to a file, but it had two downsides:

    1. it can't take an existing patch file as input (it can only generate a new diff between two input files)
    2. the ui is oldschool, not fancy colors, etc.

    So I wanted to write a sort of "modern sdiff". I peeked into the code a bit and it turns out sdiff just shells out to diff to perform the diffing between two files, using popen(). I realized we didn't have this in core, plus a couple of other libc functions so I figured it might be useful to wrap them, e.g.

    (register popen (Fn [(Ptr CChar) (Ptr CChar)] (Ptr FILE)))                                                                                                                  
    (register pclose (Fn [(Ptr FILE)] Int))                                                                                                                                     
    (register fgets (Fn [(Ptr CChar) Int (Ptr FILE)] (Ptr CChar)))                                                                                                              
    (register PATH_MAX Int)                                                                                                                                                     
    
    (defn main []                                                                                                                                                               
      (let [fp (popen (cstr "ls *") (cstr "r"))                                                                                                                                 
            path (cstr &(String.allocate PATH_MAX \a))                                                                                                                          
            status 0]                                                                                                                                                           
        (do (while (not-null? (fgets path PATH_MAX fp))                                                                                                                         
              (IO.println &(from-cstr path)))                                                                                                                                   
            (set! status (pclose fp))                                                                                                                                           
            (if (= status -1)                                                                                                                                                   
                (IO.println "error!")                                                                                                                                           
                (System.exit 0))))                                                                                                                                              
    )
    Though I think for an actual wrapper we'd want a helper so that we can use String instead of Ptr CChar
    also might be nice to provide types for things like file modes
    actually, is there a way to do &(String.allocate PATH_MAX \a) to just allocate an empty string w/o filling with arbitrary characters?
    Scott Olsen
    @scolsen
    anyone have solutions for passing literals to C? There are some situations in which it's necessary, e.g. the c11 static_assert macro will only take a string literal, but because carp manages strings it tends to output a variable name in the literal position, e.g.
    (Libc.Assert.static-assert 0 (cstr "foo"))
    out/main.c:9445:22: error: expected string literal for diagnostic message in static_assert
        static_assert(0, _8);
    Veit Heller
    @hellerve
    what happens if you just pass the literals as is?
    Tim Dévé
    @timdeve:matrix.org
    [m]
    Really? In my memory if you let's say register static_assert, then use it with the literal directly (static-assert "my literal") it get emitted asstatic_assert("my literal"). Are you saying it it emits "char* v1 = "my literal"; static_assert(v1);?
    Ah but you calling cstr on it first no? What if you register your parameter as (Ref String) instead (Ptr CChar)?
    Tim Dévé
    @timdeve:matrix.org
    [m]
    Nevermind I just checked it does do a bunch of intermediate variables...
    I did think it would be nice to have the equivalent of deftemplate before but that emits an builtin/special form rather than a function. Might be useful to wrap macros.
    Veit Heller
    @hellerve
    purescript 0.14 looks exciting:
    Tim Dévé
    @timdeve:matrix.org
    [m]
    I really want to play with Gleam but I barely have the time to do anything with Carp already...
    https://blog.pd-andy.dev/phantom-types-in-gleam
    Veit Heller
    @hellerve
    ive never heard of gleam
    Tim Dévé
    @timdeve:matrix.org
    [m]
    Statically typed language that runs on the BEAM (erlang VM)
    Veit Heller
    @hellerve
    neat
    wasnt there a haskell-like one as well, for a while?
    Tim Dévé
    @timdeve:matrix.org
    [m]
    I know of the Erlang backed for Purescript.
    Veit Heller
    @hellerve
    that also exists, right
    i was thinking of alpaca (https://github.com/alpaca-lang/alpaca)
    Tim Dévé
    @timdeve:matrix.org
    [m]
    Ah didn't know that one.
    Veit Heller
    @hellerve
    i built a compiler from my first real lisp into erlang core back in the day and checked out all the beam languages
    though i think only lfe was around then
    Tim Dévé
    @timdeve:matrix.org
    [m]
    How did you find the BEAM Bytecode to work with?
    Or did you emit erlang code?
    Veit Heller
    @hellerve
    i emitted an intermediate representation
    there is like one paper about it
    maybe these days there is more
    let me find it
    the representation is actually called core erlang
    so i basically just used that 6 page paper and some repl exploration
    it never really worked i think
    back in the day i had never written a compiler before, and of course i wanted to write a nanopass-multi backend compiler from the get-go
    i vastly overestimated my abilities i guess :sweat_smile:
    Veit Heller
    @hellerve
    i’m going full disclosure: i’m stuck with the env rewrite, and i feel it drains my capacities at the moment. i think i will switch projects for now, since i think there are lots of nice smaller things i could spend some time on and make better headway. sorry!
    1 reply
    Tim Dévé
    @timdeve:matrix.org
    [m]
    Sounds sensible, hopefully you can come back to it with a fresh set of eyes later.
    Veit Heller
    @hellerve
    :i doesn’t seem to work on the macros in Macros.carp anymore?
    Veit Heller
    @hellerve
    i’m building a little utility to annotate a carp ast in dynamic carp. it’s extremely basic for now. i don’t know whether and if so, how it’s ever going to be useful. but it’s very fun to write!
    Erik Svedäng
    @eriksvedang:matrix.org
    [m]
    Oh, cool!
    Veit Heller
    @hellerve
    right now it just goes through s expressions and annotates types and so on and returns maps
    it feels like it could be useful anyway :sweat_smile: