Skip Navigation

Posts
130
Comments
353
Joined
2 yr. ago

Concatenative Programming @programming.dev

zeroflag/equinox: Forth Programming Language on Lua

Concatenative Programming @programming.dev

Intensional Joy (a concatenative account of internal structure) — Christine's World Wide Web Site

Concatenative Programming @programming.dev

Advanced Typechecking for Stack-Based Languages

Concatenative Programming @programming.dev

hex programming language

Concatenative Programming @programming.dev

BUND: concatenative language interpreter and shell

Concatenative Programming @programming.dev

BlagojeBlagojevic/blang: Fort [sic?] like lang

Concatenative Programming @programming.dev

Release 0.0.0-alpha1 · roc-lang/roc

  • 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
    
      
  • Concatenative Programming @programming.dev

    Tacit Talk: a podcast about programming languages, combinators, algorithms and more!

  • 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 /
    
      
  • Concatenative Programming @programming.dev

    Designing Code For Forward Progress

    Concatenative Programming @programming.dev

    Spreadsheets 1/3 - Rye Language

    Concatenative Programming @programming.dev

    ngp/tsk | A filesystem-based task manager

    Concatenative Programming @programming.dev

    Derangements | Re: Factor

  • 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.

  • Concatenative Programming @programming.dev

    Zen of Factor | Re: Factor

    Concatenative Programming @programming.dev

    Watching Code | Re: Factor

  • 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

  • Factor

    Better viewed on GitHub.

  • Day 4

    Better viewed 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.

  • Factor

     
        
    : get-input ( -- corrupted-input )
      "vocab:aoc-2024/03/input.txt" utf8 file-contents ;
    
    : get-muls ( corrupted-input -- instructions )
      R/ mul\(\d+,\d+\)/ all-matching-subseqs ;
    
    : process-mul ( instruction -- n )
      R/ \d+/ all-matching-subseqs
      [ string>number ] map-product ;
    
    : solve ( corrupted-input -- n )
      get-muls [ process-mul ] map-sum ;
    
    : part1 ( -- n )
      get-input solve ;
    
    : part2 ( -- n )
      get-input
      R/ don't\(\)(.|\n)*?do\(\)/ split concat
      R/ don't\(\)(.|\n)*/ "" re-replace
      solve ;
    
      
  • Factor

     
        
    : get-input ( -- reports )
      "vocab:aoc-2024/02/input.txt" utf8 file-lines
      [ split-words [ string>number ] map ] map ;
    
    : slanted? ( report -- ? )
      { [ [ > ] monotonic? ] [ [ < ] monotonic? ] } || ;
    
    : gradual? ( report -- ? )
      [ - abs 1 3 between? ] monotonic? ;
    
    : safe? ( report -- ? )
      { [ slanted? ] [ gradual? ] } && ;
    
    : part1 ( -- n )
      get-input [ safe? ] count ;
    
    : fuzzy-reports ( report -- reports )
      dup length <iota> [ remove-nth-of ] with map ;
    
    : tolerable? ( report -- ? )
      { [ safe? ] [ fuzzy-reports [ safe? ] any? ] } || ;
    
    : part2 ( -- n )
      get-input [ tolerable? ] count ;
    
      
  • Factor

     
        
    : get-input ( -- left-list right-list )
      "vocab:aoc-2024/01/input.txt" utf8 file-lines
      [ split-words harvest ] map unzip
      [ [ string>number ] map ] bi@ ;
    
    : part1 ( -- n )
      get-input
      [ sort ] bi@
      [ - abs ] 2map-sum ;
    
    : part2 ( -- n )
      get-input
      histogram
      '[ dup _ at 0 or * ] map-sum ;
    
      

    https://github.com/AndydeCleyre/aoc-2024

  • Day 3

    Image:

  • Day 2:

    Image:

  • Concatenative Programming @programming.dev

    Happy Advent of Code 2024 Everyone!

    Concatenative Programming @programming.dev

    NeoHaskell

    Concatenative Programming @programming.dev

    ChipWits' 40th Birthday: Original FORTH Code Open Sourced! - ChipWits Robot Coding Game

    Concatenative Programming @programming.dev

    Release v1.0.0 · marcopaganini/rpn

    Concatenative Programming @programming.dev

    Finding Subsequences | Re: Factor

    Concatenative Programming @programming.dev

    Removing Subdomains | Re: Factor