Changeset 12397 in project


Ignore:
Timestamp:
11/07/08 10:48:27 (12 years ago)
Author:
felix winkelmann
Message:

added a few pages; updated some

Location:
wiki/eggref/4
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/dissector

    r12395 r12397  
    2020or via IRC in {{#scheme}} or in {{#chicken}} on [[http://freenode.net|Freenode]] ({{irc.freenode.net}}).
    2121
    22 === Requirements
    23 
    24 [[syntax-case]]
    25 
    2622=== Download
    2723
     
    3632command reader for commands that the user uses to interactively browse
    3733the objects.
     34
     35This extension defines the module {{dissector}}.
     36
     37
     38==== Usage
     39
     40{{(require-extension dissector)}}
    3841
    3942
     
    225228=== Changelog
    226229
     230* 1.7.5 Ported to chicken4, several bugfixes
    227231* 1.7.4 Fixed several bugs reported by Andre Kuehne
    228 * 1.7.3 Removed incorrect redefintion of {{fold}} [Reed Sheridan]
     232* 1.7.3 Removed incorrect redefinition of {{fold}} [Reed Sheridan]
    229233* 1.7.2 Renamed {{tagged-pointer?}} which shadowed a primitive function [Thanks to Reed Sheridan]
    230234* 1.7.1 Replaced use of {{(end-of-file)}} with {{#!eof}}
  • wiki/eggref/4/easyffi

    r12166 r12397  
    131131using an API, or you can load it as a compiler extension. To do the latter, pass {{-X easyffi}} to {{csc}} (or {{-extend easyffi}} to
    132132{{chicken}}). {{-R easyffi}} works also, but will not make the special read-syntax available.
     133
     134This extension defines the {{easyffi}} module.
    133135
    134136To see the expanded code generated during compilation, compile with {{-debug F}}.
  • wiki/eggref/4/htmlprag

    r12166 r12397  
    44
    55A ''permissive'' HTML parser that generates SXML.
     6
     7== Usage
     8
     9{{(require-extension htmlprag)}}
     10
     11This extension provides the module {{htmlprag}}.
    612
    713== Documentation
     
    1723
    1824[[http://www.neilvandyke.org/|Neil van Dyke]]
    19 
    20 === Requirements
    21 
    22 [[http://www.call-with-current-continuation.org/eggs/syntax-case.html|syntax-case]]
    2325
    2426=== Version history
  • wiki/eggref/4/lazy-ffi

    r12395 r12397  
    2222[[http://www.call-with-current-continuation.org/eggs/lazy-ffi.egg|lazy-ffi.egg]]
    2323
     24=== Usage
     25
     26{{(require-extension lazy-ffi)}}
     27
     28This extension defines the module {{lazy-ffi}}.
     29
    2430=== Documentation
    25 
    26 To use this extension in compiled code, invoke the compiler with
    27 {{-extension lazy-ffi}} (in addition to do the {{require-extension}}).
    28 This is necessary because the extension defines a special read-syntax
    29 which has to be registered before the source code is read in. This is
    30 not needed in interpreted code.
    3131
    3232A very easy to use foreign function interface, which provides a
     
    3636{{dlopen(3)}}) to load shared libraries and construct foreign calls at
    3737runtime and in interpreted code.
     38
     39To use this extension in compiled code, invoke the compiler with
     40{{-extension lazy-ffi}}.  This is necessary because the extension
     41defines a special read-syntax which has to be registered before the
     42source code is read in. This is not required for interpreted code.
    3843
    3944Note: the libffi package is actively under development, but the
     
    163168;; Compile like this:
    164169;
    165 ; $ csc -R lazy-ffi.scm gtkhello.scm
     170; $ csc -X lazy-ffi.scm gtkhello.scm
    166171
    167172(use lazy-ffi)
     
    235240=== Changelog
    236241
     242* 1.8.2 Ported to chicken4
    237243* 1.8 Removed use of {{___callback}}
    238244* 1.7 Uses externalized easyffi extension, uses more modern CHICKEN features
  • wiki/eggref/4/matchable

    r12166 r12397  
    33== Introduction
    44
    5 Matchable is a drop-in compatible replacement for Chicken's MATCH
    6 macro.  All forms are provided under the same name, and all
    7 features except the ..k pattern are supported.
    8 
    9 In addition, matchable supports non-linear patterns,
    10 i.e. patterns where an identifier occurs multiple times,
    11 requiring all instances of the identifier to be EQUAL?.  For
    12 example:
    13 
    14   (x _ x)
    15 
    16 matches all lists of three elements whose first and third
    17 elements are the same.
    18 
    19 For full documentation, see
    20 [[http://chicken.wiki.br/Pattern%20matching|Pattern matching]]. However, the {{match-error-control}} and {{match-error-procedure}} procedures have no impact. A failure to match always signals an error.
    21 
    22 == Requirements
    23 
    24 Any {{syntax-rules}} implementation, such as
    25 [[http://www.call-with-current-continuation.org/eggs/syntax-case.html|syntax-case]],
    26 [[syntactic-closures]], [[riaxpander]] or [[alexpander]].
     5This extension implements Andrew Wright's
     6pattern matching macros.
     7
     8== Author
     9
     10[[Alex Shinn]]
     11
     12== Usage
     13
     14{{(require-extension matchable)}}
     15
     16This extension provides the {{matchable}} module.
     17
     18== Description
     19
     20(This description has been taken mostly from Andrew Wright's postscript
     21document)
     22
     23Pattern matching allows complicated control decisions based on data
     24structure to be expressed in a concise manner.  Pattern matching is
     25found in several modern languages, notably Standard ML, Haskell and
     26Miranda. These syntactic extensions internally use the {{match}}
     27library unit.
     28
     29Note: this pattern matching package is not compatible with hygienic
     30macro-expanders like the {{syntax-case}} extension (available
     31separately).
     32
     33The basic form of pattern matching expression is:
     34
     35<enscript highlight=scheme>
     36(match exp [pat body] ...)
     37</enscript>
     38
     39where {{exp}} is an expression, {{pat}} is a pattern, and
     40{{body}} is one or more expressions
     41(like the body of a lambda-expression).
     42The {{match}} form matches its first subexpression against a sequence
     43of patterns, and branches to the {{body}}
     44corresponding to the first pattern successfully matched.
     45For example, the following code defines the usual {{map}} function:
     46
     47<enscript highlight=scheme>
     48(define map
     49  (lambda (f l)
     50    (match l
     51      [() '()]
     52      [(x . y) (cons (f x) (map f y))])))
     53</enscript>
     54
     55The first pattern {{()}} matches the empty list.  The second pattern
     56{{(x . y)}} matches a pair, binding {{x}} to the first component of
     57the pair and {{y}} to the second component of the pair.
     58
     59
     60=== Pattern Matching Expressions
     61
     62The complete syntax of the pattern matching expressions follows:
     63
     64 exp ::= (match exp clause ...)
     65      |  (match-lambda clause ...)
     66      |  (match-lambda* clause ...)
     67      |  (match-let ([pat exp] ...) body)
     68      |  (match-let* ([pat exp] ...) body)
     69      |  (match-letrec ([pat exp] ...) body)
     70      |  (match-let var ([pat exp] ...) body)
     71      |  (match-define pat exp)
     72
     73 clause ::= [pat body]
     74         |  [pat (=> identifier) body]
     75
     76 pat ::= identifier           matches anything, and binds identifier as a variable
     77      |  _                    anything
     78      |  ()                   itself (the empty list)
     79      |  #t                   itself
     80      |  #f                   itself
     81      |  string               an `equal?' string
     82      |  number               an `equal?' number
     83      |  character            an `equal?' character
     84      |  's-expression        an `equal?' s-expression
     85      |  (pat-1 ... pat-n)    a proper list of n elements
     86      |  (pat-1 ... pat-n . pat-n+1) 
     87                              a list of n or more elements
     88      |  (pat-1 ... pat-n pat-n+1 ...) 
     89                              a proper list of n+k or more elements [1]
     90      |  #(pat-1 ... pat-n)   a vector of n elements
     91      |  #(pat-1 ... pat-n pat-n+1 ...) 
     92                              a vector of n+k or more elements
     93      |  ($ struct pat-1 ... pat-n) 
     94                              a structure
     95      |  (= field pat)        a field of a structure
     96      |  (and pat-1 ... pat-n) 
     97                              if all of pat-1 through pat-n match
     98      |  (or pat-1 ... pat-n)
     99                              if any of pat-1 through pat-n match
     100      |  (not pat-1 ... pat-n)
     101                              if none of pat-1 through pat-n match
     102      |  (? predicate pat-1 ... pat-n) 
     103                              if predicate true and pat-1 through pat-n all match
     104      |  (set! identifier)    anything, and binds identifier as a setter
     105      |  (get! identifier)    anything, and binds identifier as a getter
     106      |  `qp                  a quasipattern
     107
     108 qp ::= ()                    itself (the empty list)
     109     |  #t                    itself
     110     |  #f                    itself
     111     |  string                an `equal?' string
     112     |  number                an `equal?' number
     113     |  character             an `equal?' character
     114     |  symbol                an `equal?' symbol
     115     |  (qp-1 ... qp-n)       a proper list of n elements
     116     |  (qp-1 ... qp-n . qp-n+1) 
     117                              a list of n or more elements
     118     |  (qp-1 ... qp-n qp-n+1 ...) 
     119                              a proper list of n+k or more elements
     120     |  #(qp-1 ... qp-n)      a vector of n elements
     121     |  #(qp-1 ... qp-n qp-n+1 ...) 
     122                              a vector of n+k or more elements
     123     |  ,pat                  a pattern
     124     |  ,@pat                 a pattern, spliced
     125
     126The next subsection describes the various patterns.
     127
     128The {{match-lambda}} and {{match-lambda*}} forms are convenient
     129combinations of {{match}} and {{lambda}}, and can be explained
     130as follows:
     131
     132<enscript highlight=scheme>
     133(match-lambda [pat body] ...)   =  (lambda (x) (match x [pat body] ...))
     134(match-lambda* [pat body] ...)  =  (lambda x (match x [pat body] ...))
     135</enscript>
     136
     137where {{x}} is a unique variable.
     138The {{match-lambda}} form is convenient when defining a single argument
     139function that immediately destructures its argument.
     140The {{match-lambda*}} form constructs a function that accepts any number
     141of arguments; the patterns of {{match-lambda*}} should be lists.
     142
     143The {{match-let}}, {{match-let*}}, {{match-letrec}},
     144and {{match-define}} forms generalize
     145Scheme's {{let}}, {{let*}}, {{letrec}}, and {{define}}
     146expressions to allow
     147patterns in the binding position rather than just variables.
     148For example, the following expression:
     149
     150<enscript highlight=scheme>
     151(match-let ([(x y z) (list 1 2 3)]) body ...)
     152</enscript>
     153
     154binds {{x}} to 1, {{y}} to 2, and {{z}} to 3 in {{body ...}}.
     155These forms are convenient for destructuring the result
     156of a function that returns multiple values as a list or vector.
     157As usual for {{letrec}} and {{define}},
     158pattern variables bound by {{match-letrec}} and {{match-define}}
     159should not be used in computing the bound value.
     160
     161The {{match}}, {{match-lambda}}, and {{match-lambda*}} forms
     162allow the optional syntax {{(=> identifier)}} between the pattern
     163and the body of a clause.  When the pattern match for such a clause
     164succeeds, the {{identifier}} is bound to a `failure
     165procedure' of zero arguments within the {{body}}.  If this
     166procedure is invoked, it jumps back to the pattern matching
     167expression, and resumes the matching process as if the pattern had
     168failed to match.  The {{body}} must not mutate the object being
     169matched, otherwise unpredictable behavior may result.
     170
     171
     172=== Patterns
     173
     174{{identifier}}: (excluding the reserved names
     175{{?}}, {{,}}, {{=}}, {{_}}, {{and}}, {{or}}, {{not}}, {{set!}}, {{get!}} and {{...}})
     176matches anything, and binds a variable of this name to
     177the matching value in the {{body}}.
     178
     179{{_}}:
     180matches anything, without binding any variables.
     181
     182{{()}}, {{#t}}, {{#f}}, {{string}}, {{number}},
     183{{character}}, '{{s-expression}}:
     184These constant patterns match themselves, i.e.,
     185the corresponding value must be {{equal?}} to the pattern.
     186
     187{{(pat-1 ... pat-n)}}:
     188matches a proper list of {{n}} elements
     189that match {{pat-1}} through {{pat-n}}.
     190
     191{{(pat-1 ... pat-n . pat-n+1)}}:
     192matches a (possibly improper) list of at least {{n}}
     193elements that ends in
     194something matching {{pat-n+1}}.
     195
     196{{(pat-1 ... pat-n pat-n+1 ...)}}:
     197matches a proper list of {{n}} or more elements, where
     198each element of the tail matches {{pat-n+1}}.  Each pattern variable in
     199{{pat-n+1}} is bound to a list of the matching values.  For example,
     200the expression:
     201
     202<enscript highlight=scheme>
     203(match '(let ([x 1][y 2]) z)
     204  [('let ((binding values) ...) exp)  body])
     205</enscript>
     206
     207binds {{binding}} to the list {{'(x y)}},
     208{{values}} to the list \{{'(1 2)}},
     209and {{exp}} to {{'z}}
     210in the body of the {{match}}-expression.
     211For the special case where {{pat-n+1}} is a pattern variable, the list
     212bound to that variable may share with the matched value.
     213
     214{{(pat-1 ... pat-n pat-n+1 ___)}}:
     215This pattern means the same thing as the previous pattern.
     216
     217{{#(pat-1 ... pat-n)}}:
     218matches a vector of length {{n}}, whose elements match
     219{{pat-1}} through {{pat-n}}.
     220
     221{{#(pat-1 ... pat-n pat-n+1 ...)}}:
     222matches a vector of length {{n}} or more, where each element
     223beyond {{n}} matches {{pat-n+1}}.
     224
     225{{($ struct pat-1 ... pat-n)}}:
     226matches a structure
     227declared with {{define-record}} or {{define-record-type}}.
     228
     229{{(= field pat)}}:
     230is intended for selecting a field from a structure.  ''field'' may be
     231any expression; it is applied to the value being matched, and the
     232result of this application is matched against {{pat}}.
     233
     234{{(and pat-1 ... pat-n)}}:
     235matches if all of the subpatterns match.
     236At least one subpattern must be present.
     237This pattern is often used as {{(and x pat)}} to bind {{x}} to
     238to the entire value that matches {{pat}}
     239(cf. ''as-patterns'' in ML or Haskell).
     240
     241{{(or pat-1 ... pat-n)}}:
     242matches if any of the subpatterns match.
     243At least one subpattern must be present.
     244All subpatterns must bind the same set of pattern variables.
     245
     246{{(not pat-1 ... pat-n)}}:
     247matches if none of the subpatterns match.
     248At least one subpattern must be present.
     249The subpatterns may not bind any pattern variables.
     250
     251{{(? predicate pat-1 ... pat-n)}}:
     252In this pattern,
     253{{predicate}} must be an expression evaluating to a single argument
     254function.
     255This pattern matches if {{predicate}} applied to the corresponding value
     256is true, and the subpatterns {{pat-1 ... pat-n}} all match.
     257The {{predicate}} should not have side effects, as
     258the code generated by the pattern matcher may invoke predicates repeatedly
     259in any order.
     260The {{predicate}} expression is bound in the same scope as the
     261match expression, i.e.,
     262free variables in {{predicate}} are not bound by pattern variables.
     263
     264{{(set! identifier)}}:
     265matches anything, and binds {{identifier}}
     266to a procedure of one argument that mutates the corresponding field of
     267the matching value.
     268This pattern must be nested within a pair, vector, box, or structure
     269pattern. For example, the expression:
     270
     271<enscript highlight=scheme>
     272(define x (list 1 (list 2 3)))
     273(match x [(_ (_ (set! setit)))  (setit 4)])
     274</enscript>
     275
     276mutates the {{cadadr}} of {{x}} to 4, so that {{x}} is
     277{{'(1 (2 4))}}.
     278
     279{{(get! identifier)}}:
     280matches anything, and binds {{identifier}}
     281to a procedure of zero arguments that accesses the corresponding field of
     282the matching value.  This pattern is the complement to {{set!}}.
     283As with {{set!}},
     284this pattern must be nested within a pair, vector, box, or structure
     285pattern.
     286
     287''Quasipatterns'':
     288Quasiquote introduces a quasipattern, in which identifiers are considered
     289to be symbolic constants.  Like Scheme's quasiquote for data,
     290{{unquote}} (,) and {{unquote-splicing}} (,@) escape back to
     291normal patterns.
     292
     293=== Record Structures Pattern
     294
     295The {{$}} pattern handles native record structures and
     296[[http://srfi.schemers.org/srfi-9/srfi-9.html|SRFI-9]] records
     297transparently.  Currently it is required that
     298[[http://srfi.schemers.org/srfi-9/srfi-9.html|SRFI-9]] record
     299predicates are named exactly like the record type name, followed by a
     300{{?}} (question mark) character.
     301
    27302
    28303== License
     
    32307== Download
    33308
    34 http://www.call-with-current-continuation.org/eggs/atchable.egg
     309http://www.call-with-current-continuation.org/eggs/matchable.egg
    35310
    36311== History
Note: See TracChangeset for help on using the changeset viewer.