Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Add "anonymous var" #150

Open
porky11 opened this issue Nov 20, 2016 · 0 comments
Open

Suggestion: Add "anonymous var" #150

porky11 opened this issue Nov 20, 2016 · 0 comments

Comments

@porky11
Copy link
Contributor

porky11 commented Nov 20, 2016

The type-annotation in (def … (var …)) has 3 use cases:
a: declaring variables uninitialized
b: ensure type of a form
c: type-dependant initializing

These abilities may be useful without declaring vars too.

;;;a:
(fun (type-prototype int)) ;;function needs int, but doesn't use it in this case, or only needs it for dispatch

;;;b:
(g (assert-type T (f x))) ;;(f x) has to be T, but will be passed to function immeditely, similar to `(the T x)` in CL

;;;c:
(make uint16 1) ;;instead of `(cast 1 uint16)`
(make (array-of 2 float) (array 1.0 2.0)) ;;instead of `(array-of 2 float (array 1.0 2.0))`
(make T ((value 1))) ;;instead of (T (value 1))
;;this makes initializing more uniform

all these functionalities can also be expressed as a single function. Let's call it var.
with this every varialbe type declaration like (let ((a T [val])) …) can be written as (let ((a \ (var T [val]))) …).

So the type annotation could be dropped entirely (which is \ mostly in my code anyway).
Maybe this will make the code more clear, becuase types are only derived from the value.
But an "anonymous var" is also useful without dropping the type annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant