Skip Navigation

Posts
184
Comments
355
Joined
2 yr. ago

Concatenative Programming @programming.dev

Drunken Bishop (2023)

Concatenative Programming @programming.dev

Jovial Reverse Polish Notation Calculators

Concatenative Programming @programming.dev

Left to Right | Re: Factor

Concatenative Programming @programming.dev

Pickle | Re: Factor

Concatenative Programming @programming.dev

Marp | Re: Factor

Concatenative Programming @programming.dev

yumaikas/onion: Stack language compiled to lua

Concatenative Programming @programming.dev

Subset Park: Combinatory Programming

Concatenative Programming @programming.dev

Tribonacci Numbers | Re: Factor

Concatenative Programming @programming.dev

Tak Function – Re: Factor

Concatenative Programming @programming.dev

Forj: Looking for co-developers/co-designers for homoiconic stack based systems programming language development

Concatenative Programming @programming.dev

Ask OK? | Re: Factor

Concatenative Programming @programming.dev

Asserting Implications – Re: Factor

  • What font is used in the "DEMAND A NEW NORMAL" banner?

  • Concatenative Programming @programming.dev

    World Emoji Day – Re: Factor

    Concatenative Programming @programming.dev

    One Billion Loops – Re: Factor

    Concatenative Programming @programming.dev

    Command Arguments | Re: Factor

    Concatenative Programming @programming.dev

    Fibonacci Style – Re: Factor

    Concatenative Programming @programming.dev

    Tiny Great Languages: MOUSE (2024)

    Concatenative Programming @programming.dev

    LeoMehraban/factor-lsp: A buggy lsp for factor

    Concatenative Programming @programming.dev

    Nix Developer Setup for Factor | toastal

    Concatenative Programming @programming.dev

    Mathematical Illustrations: A Manual of Geometry and PostScript (1996-2004)

  • I don't know how they picked the name for this new terminal, maybe it's a reference.

  • It is very good, and I am currently using it. I don't like its dependencies on GTK stuff, the developer is a little picky about what to support, and I dislike the +options style. Other than that, 👍 .

    Also great: Wezterm, Konsole, Rio. I'm excitedly following Rio's development, which has a much smaller dependency list, and hopping back and forth between it and Ghostty/Wezterm. But it's still got some things to iron out and features to develop.

  • A bit from the readme appreciating concatenative programming:

    The Joy language introduced concatenative functional programming. This generally means a stack based virtual machine, and a program consisting of words which are functions taking an input stack and returning an output stack. The natural syntax that results is postfix. Over a very long time I have come to feel that syntax gets in between me and the power in a language. Postfix is the least syntax possible.

    There are several reasons I like the concatenative style of programming:

    • Function composition is concatenation.
    • Pipelining values through functions to get new values is the most natural idiom.
    • Functions are applied from left to right instead of inside out.
    • Support for multiple return values comes for free.
    • No need for operator precedence.
    • Fewer delimiters are required:
      • Parentheses are not needed to control operator precedence.
      • Semicolons are not needed to separate statements.
      • Commas are not needed to separate arguments.

    (Note: Sapf is inspired by, but is not purely a concatenative language because it has lexical variables.)

    When I am programming interactively, I most often find myself in the situation where I have a value and I want to transform it to something else. The thing to do is apply a function with some parameters. With concatenative programming this is very natural. You string along several words and get a new value.

  • It's been a while, but my clumsy adding of a comment to the buffer is unnecessary, given zle -M, which will display a message outside of the buffer. So here's an updated version:

     bash
        
    # -- Run input if single line, otherwise insert newline --
    # Key: enter
    # Credit: https://programming.dev/comment/2479198
    .zle_accept-except-multiline () {
      if [[ $BUFFER != *$'\n'* ]] {
        zle .accept-line
        return
      } else {
        zle .self-insert-unmeta
        zle -M 'Use alt+enter to submit this multiline input'
      }
    }
    zle -N       .zle_accept-except-multiline
    bindkey '^M' .zle_accept-except-multiline  # Enter
    
    # -- Run input if multiline, otherwise insert newline --
    # Key: alt+enter
    # Credit: https://programming.dev/comment/2479198
    .zle_accept-only-multiline () {
      if [[ $BUFFER == *$'\n'* ]] {
        zle .accept-line
      } else {
        zle .self-insert-unmeta
      }
    }
    zle -N         .zle_accept-only-multiline
    bindkey '^[^M' .zle_accept-only-multiline  # Enter
    
      
  • The given Uiua example (mercifully given using words rather than the symbols):

     
            [3 4 5 10 23]
        divide length on /+
    
    
      

    For all the talk about "forward" it's uncomfortable to me how the Uiua evaluation within a line happens backward.

    An equivalent in Factor, where keep is close to on:

     
            { 3 4 5 10 23 }
        [ sum ] keep length /
    
    
      

    But this pattern of doing two things in sequence to the same item is common enough that bi is handy:

     
            { 3 4 5 10 23 }
        [ sum ] [ length ] bi /
    
      
  • Slow and dumb gets it done! I may revisit this when I give up on future days.

  • Nothing smart to see here. I may revisit this when I give up on future days.

  • Factor

     
        
    : get-input ( -- rules updates )
      "vocab:aoc-2024/05/input.txt" utf8 file-lines
      { "" } split1
      "|" "," [ '[ [ _ split ] map ] ] bi@ bi* ;
    
    : relevant-rules ( rules update -- rules' )
      '[ [ _ in? ] all? ] filter ;
    
    : compliant? ( rules update -- ? )
      [ relevant-rules ] keep-under
      [ [ index* ] with map first2 < ] with all? ;
    
    : middle-number ( update -- n )
      dup length 2 /i nth-of string>number ;
    
    : part1 ( -- n )
      get-input
      [ compliant? ] with
      [ middle-number ] filter-map sum ;
    
    : compare-pages ( rules page1 page2 -- <=> )
      [ 2array relevant-rules ] keep-under
      [ drop +eq+ ] [ first index zero? +gt+ +lt+ ? ] if-empty ;
    
    : correct-update ( rules update -- update' )
      [ swapd compare-pages ] with sort-with ;
    
    : part2 ( -- n )
      get-input dupd
      [ compliant? ] with reject
      [ correct-update middle-number ] with map-sum ;
    
      

    on GitHub

  • More Factor solutions for the first 3 days (at time of comment) from okflo, on sourcehut.

  • Have you had a good look at Factor? FWIW I've got at least the first 3 days with it up here.

  • Some more Factor solutions for the first 3 days (so far) from soweli Niko, on Codeberg.