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

Array primitives #62

Merged
merged 8 commits into from
Nov 8, 2018
Merged

Array primitives #62

merged 8 commits into from
Nov 8, 2018

Conversation

nomeata
Copy link
Collaborator

@nomeata nomeata commented Nov 7, 2018

As requested in #57.

@nomeata nomeata requested a review from rossberg November 7, 2018 16:57
@nomeata
Copy link
Collaborator Author

nomeata commented Nov 7, 2018

@paulyoung here is something for you to play with.

@@ -34,6 +34,16 @@ class revrange(x : Nat, y : Nat) {

func printInt (x : Int) { ((prim "printInt") : Int -> ()) x };
func print (x : Text) { ((prim "print") : Text -> ()) x };

/* This would be nicer as a objects, but lets do them as functions
until the compiler has a concept of “static objects” */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been wondering about this 😃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some context: I've run into naming collisions quite a bit, and while I can fix that myself right now I imagine at some point people will want to depend on ActorScript code that they didn't write and there's no way to qualify names that conflict.

src/prelude.ml Outdated Show resolved Hide resolved
@paulyoung
Copy link
Contributor

I think this is working as expected.

Am I correct in saying that a simple way to think of these 2 functions is:

  1. Use init when you want to create a mutable array
  2. Use tabulate when you want to create an immutable array

@nomeata
Copy link
Collaborator Author

nomeata commented Nov 7, 2018

Precisely!

Copy link
Contributor

@paulyoung paulyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my perspective but I haven't reviewed the OCaml code at all.

@nomeata nomeata changed the title Array primitives (#57) Array primitives Nov 8, 2018
src/prelude.ml Outdated
| [len; g] ->
let len_nat = Int.to_int (as_nat len) in
let (_, g') = Value.as_func g in
let rec go prefix k i =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: some indentation seems to be off here

(I should auto-configure vim to have the right settings also for Ocaml)
@nomeata nomeata merged commit 5824c75 into master Nov 8, 2018
@nomeata nomeata deleted the array_funs branch November 8, 2018 15:45
dfinity-bot added a commit that referenced this pull request Dec 2, 2021
mergify bot pushed a commit that referenced this pull request Dec 2, 2021
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

Successfully merging this pull request may close these issues.

None yet

3 participants