destructuring | = | Origin_0x4EABEDF1 |
contains behavior related to the definition of different concepts
-
none
- aliasMethod(oldName, newName)
- dlecro(...)
- dlecrox(...)
- dmacro(...)
- dsyntax(...)
- fn([documentation] nil, +[argumentsAndBody])
- fnx(...)
- generateMatchMethod(...)
- lecro([documentation] nil, [body] nil)
- lecrox(...)
- macro([documentation] nil, [body] nil)
- method([documentation] nil, +[argumentsAndBody])
- syntax([documentation] nil, [body] nil)
- ?(...)
- ?(...)
Takes two evaluated text or symbol arguments that name the method to alias, and the new name to give it. returns the receiver.
works exactly the same as dmacro, but returns an activatable LexicalMacro instead
[ show source ]
syntax( DefaultBehavior Definitions destructuring doFor('(lecro), call) )
- - should return a LexicalMacro that is activatable
[ show source ]
foo = dlecro( [] nil) cell(:foo) kind should ==("LexicalMacro") cell(:foo) activatable should be true
- - should pass on a possible documentation string
[ show source ]
foo = dlecro( "docstring42", [](a) a code) cell(:foo) documentation should ==("docstring42")
- - should destructure a simple argument list
[ show source ]
foo = dlecro( [](a) a code) foo(abc foo bar) should ==("abc foo bar") foo(10 *(20)) should ==("10 *(20)")
works exactly the same as dmacro, but returns an inactive LexicalMacro instead
[ show source ]
syntax( DefaultBehavior Definitions destructuring doFor('(lecrox), call) )
- - should return a LexicalMacro that is not activatable
[ show source ]
foo = dlecrox( [] nil) cell(:foo) kind should ==("LexicalMacro") cell(:foo) activatable should be false
- - should pass on a possible documentation string
[ show source ]
foo = dlecrox( "docstring42", [](a) a code) cell(:foo) documentation should ==("docstring42")
- - should destructure a simple argument list
[ show source ]
foo = dlecrox( [](a) a code) foo call(abc foo bar) should ==("abc foo bar") foo call(10 *(20)) should ==("10 *(20)")
takes one optional documentation string, and one or more arguments. these argument should all begin with a literal array. This literal array will be interpreted as a destructuring pattern. the syntax macro will expand into a macro that will read dispatch based on all the patterns given. the first pattern that matches will be used. the code coming after the literal array will have access to the variables defined in the pattern. the result of this code will be the result of the macro. if no patterns match, a Condition Error Invocation condition will be signalled. the patterns can take several basic forms. the first form is that of a simple name, like this: [arg] this pattern will match exactly one argument, and assign that argument message to the name 'arg'. this message will not be evaluated. a pattern can have several arguments like this: [one, two, three] this pattern will match exactly three arguments and assign them to the names 'one', 'two' and 'three', unevaluated. if you wish to evaluate an argument before it gets assigned to the variable, you can use a literal > preceding the name, like this: [one, >two] this will take exactly two arguments, where the second will be assigned the evaluated result of the second argument while the first will get the unevaluated message. the evaluation of evaluated arguments are lazy, which means that something like this: [>cond, then] ;; do something here [>cond, then, else] ;; do something else will only evaluate the cond that is relevant to the structure. this means that if you give two arguments to the above code, only the above cond will be evaluated. and if you give three arguments only the second cond will be evaluated. the final destructuring available at the moment allows the use of a rest argument. this should generally be placed last in the patterns since a rest argument will most of the time match everything. a rest argument can be specified with [+any] the plus sign is the magic part. any name can be used. what you will get is a list of unevaluated messages matching zero or more of the argument list. rest arguments can be combined with other arguments but should be placed last in that case. a list of evaluated arguments can be generated by following the plus sign with a greater than arrow: [arg, +>moreArgs] a pattern matching list can also be empty. finally, a destructuring can also have default arguments. these will be evaluated if no matching argument can be found. the default argument for an unevaluated argument will be the message chain to unevaluated set to the default argument. the default argument for an evaluated value will be evaluated at the point, which means it can use earlier values: [arg1 2+2, >arg2 2+2] will match an empty argument list, and in that case give arg1 the message chain corresponding to 2+2, while arg2 will be set to the value 4.
[ show source ]
syntax( DefaultBehavior Definitions destructuring doFor('(macro), call) )
- - should pass on a possible documentation string
[ show source ]
foo = dmacro( "docstring42", [](a) a code) cell(:foo) documentation should ==("docstring42")
- - should destructure a simple argument list
[ show source ]
foo = dmacro( [](a) a code) foo(abc foo bar) should ==("abc foo bar") foo(10 *(20)) should ==("10 *(20)")
- - should destructure two argument lists correctly
[ show source ]
foo = dmacro( [](a) a code, [](a, b) [](a code, b code)) foo(abc foo) should ==("abc foo") foo(abc foo, bar blux) should ==([]("abc foo", "bar blux"))
- - should destructure an empty list
[ show source ]
foo = dmacro( [] 42) foo should ==(42)
- - should destructure with default value
[ show source ]
foo = dmacro( [](x 2 +(2)) x) foo code should ==("2 +(2)") foo(blarg foo) code should ==("blarg foo") foo = dmacro( [](x 2 +(2)) x, [](y 3 +(3), z 4 +(4), q 111) [](y code, z code, q code) ) foo code should ==("2 +(2)") foo(blarg foo) code should ==("blarg foo") foo(blarg foo, murg fox) should ==([]("blarg foo", "murg fox", "111")) foo(blarg foo, murg fox, 123) should ==([]("blarg foo", "murg fox", "123"))
- - should destructure an evaluated part with default value
[ show source ]
foo = dmacro( [](>(x 2 +(2))) x) foo should ==(4) foo(13) should ==(13) foo = dmacro( [](x, y, z) x, [](>(x 2 +(2)), >(y x +(13))) [](x, y) ) foo should ==([](4, 17)) foo(12) should ==([](12, 25)) foo(12, 44) should ==([](12, 44))
- - should destructure and evaluate part of destructuring
[ show source ]
foo = dmacro( [](x, >(y), z) [](x code, y, z code)) foo(abc foo, 42 +(17), murgicox) should ==([]("abc foo", 59, "murgicox"))
- - should destructure a rest argument correctly
[ show source ]
foo = dmacro( [](+(rest)) rest map(code)) foo should ==([]) foo(aha) should ==([]("aha")) foo(abc foo, 42 +(17), murgicox) should ==([]("abc foo", "42 +(17)", "murgicox")) foo = dmacro( [](one, two) nil, [](one, two, +(rest)) rest map(code) ) foo(abc foo, 42 +(17), murgicox) should ==([]("murgicox"))
- - should destructure an evaluated rest argument correctly
[ show source ]
foo = dmacro( [](+>(rest)) rest) foo should ==([]) foo("str") should ==([]("str")) xx = 42 foo(2 **(3), 42 +(17), xx) should ==([](8, 59, 42)) foo = dmacro( [](one, two) nil, [](one, two, +>(rest)) rest ) foo(abc foo, murgicox, 42 +(17)) should ==([](59))
- - should generate an error if not matching could happen
[ show source ]
foo = dmacro( [] nil) fn(foo(1)) should signal(Condition Error Invocation NoMatch)
- - should handle some extra newlines
[ show source ]
foo = dmacro( [](one) :one, [](two, three) :two) foo(1) should ==(:one) foo(1, 2) should ==(:two)
works exactly the same as dmacro, but returns a DefaultSyntax instead
[ show source ]
syntax( DefaultBehavior Definitions destructuring doFor('(syntax), call) )
creates a new lexical block that can be executed at will, while retaining a reference to the lexical closure it was created in. it will always update variables if they exist. there is currently no way of introducing shadowing variables in the local context. new variables can be created though, just like in a method. a lexical block mimics LexicalBlock, and can take arguments. at the moment these are restricted to required arguments, but support for the same argument types as DefaultMethod will come.
does the same things as fn, but returns something that is activatable.
[ show source ]
macro( call resendToMethod("fn") do( activatable = true))
takes one argument that should be the name of the match method to use. need to be called with the kind as direct receiver, either in a do-block or directly. if the match method is called 'matchFoo' and the receiver is called Foo, will generate a method that looks like this: method(other, if(self same?(Foo), Reflector other:mimics?(other, Foo), self matchFoo(other)))
[ show source ]
syntax( otherMethod = call arguments [](0) ''(method(other, if(self same?(`(self)), Reflector other:mimics?(cell(:other), `(self)), bind(rescue(Condition Error, fn(c, false)), self `(otherMethod) (other))))))
expects one code argument, optionally preceeded by a documentation string. will create a new LexicalMacro based on the code and return it.
does the same things as lecro, but returns something that is not activatable.
[ show source ]
macro( call resendToMethod("lecro") do( activatable = false))
expects one code argument, optionally preceeded by a documentation string. will create a new DefaultMacro based on the code and return it.
expects any number of unevaluated arguments. if no arguments at all are given, will just return nil. creates a new method based on the arguments. this method will be evaluated using the context of the object it's called on, and thus the definition can not refer to the outside scope where the method is defined. (there are other ways of achieving this). all arguments except the last one is expected to be names of arguments that will be used in the method. there will possible be additions to the format of arguments later on - including named parameters and optional arguments. the actual code is the last argument given.
expects one code argument, optionally preceeded by a documentation string. will create a new DefaultSyntax based on the code and return it.