Skip to content

parameterized patterns #283

Open
Open
@lutzhamel

Description

@lutzhamel

An idea on how to look at parameterized patterns. Currently Asteroid supports parameterized patterns via variables read from the environment,

Asteroid Version 2.0.1alpha
(c) University of Rhode Island
Type "asteroid -h" for help
Press CTRL-D to exit
ast> let p = pattern %integer.
ast> let pair = pattern (x:*p,y:*p).
ast> let q:*pair = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)
ast> let p = pattern %real. -- now pair is a pair of real values
ast> let q:*pair = (1,2).
error: pattern match failed: conditional pattern match failed
ast> let q:*pair = (1.1,2.2).
ast> 

This is very clumsy and prone to programming errors...think dynamically scoped functions. A nice way would be to actually have have parameters on the pattern. Something like this perhaps,

ast> let p = pattern %integer.
ast> let pair = pattern with a match (x:*a,y:*a).
ast> let q:*pair(p) = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)

or in more concise form,

ast> let pair = pattern with a match (x:*a,y:*a).
ast> let q:*pair(pattern %integer) = (1,2). -- here pair is a pair of integer values
ast> q
(1,2)
ast> let q:*pair(pattern %real) = (1.1,2.2). -- here pair is a pair of real values
ast> q
(1.1,2.2)

Metadata

Metadata

Assignees

Labels

enhancementFeatures that are directly related to the core tenet of Asteroid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions