Skip to content

Imperative block syntax, function definition syntax #11

Description

@pboyer

There is a case to be made for [Imperative] attributes for function definitions, e.g.:

[Imperative]
def : Number boolToNum( val : bool ) {
  if ( val ) { return = 1;} else { return = 0; }
}

This could also clearly be inferred.

This is an assigned imperative block, with proposed dependency capture vars:

val = true;
a = [Imperative]( val ){
  if ( val ) { return = 1;} else { return = 0; }
}
// a == 1

An assigned imperative block is thus a lot like an immediately evaluated anonymous function, in proposed syntax:

a = ([Imperative] lambda : Number ( val : bool ){ if ( val ) { return = 1;} else { return = 0; } )( false )
// a == 1

However, this form actually is more powerful, as the type declaration allows for replication to be performed:

a = ([Imperative] lambda : Number ( val : bool ){ if ( val ) { return = 1;} else { return = 0; } )( {false, true} )
// a == { 0, 1 }

IOW, the user can specify whether the the captured variables should be interpreted as a compound or singular value.

Perhaps, we can modify the Imperative block capture list to include a type annotation:

a = [Imperative]( val : bool ){ if ( val ) { return = 1;} else { return = 0; }

@lukechurch

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions