Changeset 40167 in project


Ignore:
Timestamp:
06/02/21 15:12:55 (12 days ago)
Author:
Idiomdrottning
Message:

add make-tree-accessor, make-sloppy-tree-accessor, scar, scdr, and realpath

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/brev-separate

    r40155 r40167  
     1
    12== brev-separate
    23[[toc:]]
     
    56the {{clojurian}} and {{miscmacros}} and {{(chicken base)}} genre.
    67
    7 It's called {{brev-separate}} since the full {{brev}} egg also imports
    8 and reexports a bunch of other eggs, including the aforementioned
     8It's called {{brev-separate}} since the full {{brev}} egg also imports and
     9reexports a bunch of other eggs, including the aforementioned
    910{{clojurian}} and {{miscmacros}}.
    1011
     
    3738   (pattern body) ...)
    3839
    39 It uses {{matchable}} to dispatch between different call signatures (kinda similar to how {{syntax-rules}} work) while also allowing you to {{inject}}, {{compare}}, {{strip-syntax}} and {{syntax}} inside, as per usual with ir-macros.
     40It uses {{matchable}} to dispatch between different call signatures
     41(kinda similar to how {{syntax-rules}} work) while also allowing you to
     42{{inject}}, {{compare}}, {{strip-syntax}} and {{syntax}} inside, as per usual
     43with ir-macros.
    4044
    4145Here's an example:
     
    7680⇒ 24
    7781
    78 As a rule of thumb, if you are deliberately injecting new names into the namespace that's when you are using ir-macros, and when you want to ''avoid'' doing that, use syntax-rules.
     82As a rule of thumb, if you are deliberately injecting new names into
     83the namespace that's when you are using ir-macros, and when you want
     84to ''avoid'' doing that, use syntax-rules.
    7985
    8086
     
    96102⇒ 1 2 3
    97103
    98 The pairs of bindings aren't individual paren-wrapped, just alternating between name and expression. The set of bindings as a whole has parens.
     104The pairs of bindings aren't individual paren-wrapped, just
     105alternating between name and expression. The set of bindings as a
     106whole has parens.
    99107
    100108 (define-closure (x 0 y 10) (jolly) (list (inc! x) (dec! y)))
     
    106114
    107115==== match-define
    108 {{matchable}} has {{match-lambda}} and {{match-lambda*}} as shortcuts, and they’re fantastic, but let’s also add a {{match-define}} as a shortcut on top of them.
     116{{matchable}} has {{match-lambda}} and {{match-lambda*}} as shortcuts, and
     117they’re fantastic, but let’s also add a {{match-define}} as a shortcut
     118on top of them.
    109119
    110120How about these sorta Haskell-style semantics?
     
    114124  ...)
    115125
    116 Her's an example:
     126Here's an example:
    117127
    118128 (match-define
     
    146156
    147157==== match-define-closure
    148 Combining {{match-define}} and {{define-closure}} into one glorious Voltron!
     158Combining {{match-define}} and {{define-closure}} into one glorious
     159Voltron!
    149160
    150161 (match-define-closure bindings (pat body) ...)
     
    161172⇒ 1 2 1 2
    162173
    163 Here is another example, the arity-table from Software Design for Flexibility.
     174Here is another example, the arity-table from citeSoftware Design for Flexibility.
    164175
    165176 (match-define-closure
     
    175186
    176187==== {{call-table}}, {{call-table*}}, {{call-vector}}, {{call-string}} and {{call-list}}
    177 The previous construct is generally useful so let's just provide it as {{call-table}}.
     188The previous construct is generally useful so let's just provide it as
     189{{call-table}}.
    178190
    179191 (define arity (call-table))
     
    209221Sometimes you think {{call-table}} is convenient but you only need one key.
    210222
    211 For {{call-key}}, instead just use parameters with {{make-parameter}}.
     223For {{call-key}}, just use {{make-parameter}}.
    212224
    213225But {{call-key*}} is awesome since it accumulates its values.
     
    231243
    232244==== define-some
    233 This is for making functions that implicitly returns '() on an {{empty?}} first argument. In other words, it define a body for patterns with '''some''' non-empty value as first argument, hence the name {{define-some}}.
     245This is for making functions that implicitly returns '() on an
     246{{empty?}} first argument. In other words, it define a body for patterns
     247with '''some''' non-empty value as first argument, hence the name
     248{{define-some}}.
    234249
    235250For example,
     
    288303
    289304
    290 ==== {{c}} a.k.a. 🍛 a.k.a. {{@>}}
     305==== {{c}} a.k.a. {{🍛}} a.k.a. {{@>}}
    291306This isn't the traditional c-combinator from mockingbirds and such.
    292307It's just a one-letter spelling of "curry". It's a function
     
    321336* (x y z . rest)
    322337
    323 and the fn macro automatically figures out which of those four you mean.
     338and the fn macro automatically figures out which of those four you
     339mean.
    324340
    325341
     
    331347 (cut map (lambda some-basic-bindings body ...) <>)
    332348
    333 except that the map can take any number of lists and that {{i}} is also anaphorically bound to the list index in {{body}}.
     349except that the map can take any number of lists and that {{i}} is also
     350anaphorically bound to the list index in {{body}}.
    334351
    335352Here is an example:
     
    342359
    343360==== as-list
    344 Here is a functional combinator for Scheme that lets its arguments treat their arguments as if they were lists.
     361Here is a functional combinator for Scheme that lets its arguments
     362treat their arguments as if they were lists.
    345363
    346364 ((as-list (c filter odd?)) 130752)
     
    363381Together with {{over}}:
    364382
    365  ((as-list (over (l) (if (vowel? l) l (char-upcase l)))) "fleet foxes")
     383 ((as-list (over (if (vowel? x) x (char-upcase x)))) "fleet foxes")
    366384
    367385⇒ “FLeeT FoXeS”
    368386
    369387
    370 ==== c_r
     388==== make-tree-accessors
    371389Sometimes you just need an arbitrarily long tree dereferencer.
    372390
     
    374392
    375393makes {{cddadadaddddar}} real. Works for any sequence of a's and d's.
     394
     395
     396==== make-sloppy-tree-accessors
     397As above, but uses scar and scdr instead of car and cdr.
    376398
    377399
     
    394416
    395417==== {{eif}} and {{econd}}
    396 {{eif}} is a version of {{if}} (or, to be precise, of {{aif}} since it anaphoric) that treats empty things as falsy.
     418{{eif}} is a version of {{if}} (or, to be precise, of {{aif}} since it
     419anaphoric) that treats empty things as falsy.
    397420
    398421 (eif "" it 'no)
     
    411434
    412435
     436==== {{scdr}}, and {{scar}}
     437A scar is like a car but returns '() if the pair has no car. A scdr is
     438like a cdr but returns '() if the pair has no cdr.
     439
     440
     441==== realpath
     442 (realpath filename)
     443
     444Uses current-directory to try to figure out an absolute path for
     445filename.
     446
     447
    413448=== Doing stuff
    414449
     
    424459
    425460
    426 == Author
    427 
    428 [[https://idiomdrottning.org/about|Idiomdrottning]]
    429 
    430 == Source code
    431 
     461=== Source code
    432462 git clone https://idiomdrottning.org/brev-separate
    433463
    434 == License
    435 
    436 Â© 2021 Idiomdrottning.
    437 
    438 All rights reserved.
    439 
    440 Redistribution and use in source and binary forms, with or without
    441 modification, are permitted provided that the following conditions are
    442 met:
    443 
    444 1. Redistributions of source code must retain the above copyright
    445 notice, this list of conditions and the following disclaimer:
    446 
    447 This software is provided by Idiomdrottning "as is" and any express or
    448 implied warranties, including, but not limited to, the implied
    449 warranties of merchantability and fitness for a particular purpose are
    450 disclaimed. In no event shall Idiomdrottning be liable for any direct,
    451 indirect, incidental, special, exemplary, or consequential damages
    452 (including, but not limited to, procurement of substitute goods or
    453 services; loss of use, data, or profits; or business interruption)
    454 however caused and on any theory of liability, whether in contract,
    455 strict liability, or tort (including negligence or otherwise) arising
    456 in any way out of the use of this software, even if advised of the
    457 possibility of such damage.
Note: See TracChangeset for help on using the changeset viewer.