GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

# Advent of Code 2025, day 6, part 1 -- if-while test set 'noop {return nil} # Usage: if conditional {case1} {case2} set 'if { inset args '(_if_cond _if_true _if_false) # Mass-assign sugar set '_if_pair [return noop, return _if_false] set '_if_pair [ get _if_pair (to-int (to-bool _if_false)) return _if_true ] (get _if_pair (to-int (to-bool _if_cond))) # Extra () means execute } # Usage if {conditional} {case} set 'while { inset args '(_while_cond _while_true) set '_while_pair [return noop] push _while_pair [ # Construct fn as data so we don't have to think about return [make-quote _while_true] # ..variable shadowing when recursing return [return 'while, make-quote _while_cond, make-quote _while_true] ] (get _while_pair (to-int (to-bool (_while_cond)))) }

Download link

https://files.mastodon.social/media_attachments/files/114/310/103/102/902/781/original/54dec10db669c1ed.png

Notices where this attachment appears

  1. Embed this notice
    mcc (mcc@mastodon.social)'s status on Friday, 11-Apr-2025 03:06:43 JST mcc mcc
    in reply to

    Before I can start, I need to make some utilities. By "utilities" I mean "if" and "while" statements, which again, this language currently lacks. MVP, remember. Implementing these in userland is possible! It's *ugly*, though. For `if`, I simulate branching by putting the two possible outcomes (functions) into an array, casting the condition to a bool and then the bool to an int, and using that as an index to the array.

    "while" is even more nightmarish. I don't… understand the use of make-quote.

    In conversation about a month ago from mastodon.social permalink
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.