class Myst::AnonymousFunction

Overview

A shorthand function definition with multiple clauses. AnonymousFunctions are most commonly used to define complex behavior in place of a block parameter for a function. Clauses are defined using a "stab" (->), followed by a parenthesized parameter list, then a clause body wrapped like a normal block (either with {...} or do...end).

An anonymous function must be given at least one clause to be valid.

'fn' [ '->' '(' [ param [ ',' param ]* ]? ')' [ '{' | 'do' ] body [ '}' | 'end' ] ]+ 'end'

Defined in:

myst/syntax/ast.cr

Constructors

Instance Method Summary

Instance methods inherited from class Myst::Node

accept(visitor) accept, accept_children(visitor) accept_children, at(node : Node)
at(node : Nil)
at(location : Location)
at
, at_end(node : Node)
at_end(node : Nil)
at_end(end_location : Location)
at_end
, class_desc : String class_desc, end_location : Location | Nil end_location, end_location=(end_location : Location | Nil) end_location=, location : Location | Nil location, location=(location : Location | Nil) location=

Constructor Detail

def self.new(clauses : Array(Myst::Block) = [] of Block, internal_name : String = "anonymous function") #

[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def accept_children(visitor) #

[View source]
def clauses : Array(Block) #

[View source]
def clauses=(clauses : Array(Block)) #

[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def internal_name : String #

#internal_name is used as the name of the function for use in stack traces and other reporting mechanisms. This should not be used for any other public functionality.


[View source]
def internal_name=(internal_name : String) #

#internal_name is used as the name of the function for use in stack traces and other reporting mechanisms. This should not be used for any other public functionality.


[View source]