mirror of
https://github.com/janet-lang/janet
synced 2025-01-13 00:50:26 +00:00
Merge branch 'master' of github.com:janet-lang/janet
This commit is contained in:
commit
d998f24d26
@ -1,6 +1,6 @@
|
||||
(defn dowork [name n]
|
||||
(print name " starting work...")
|
||||
(os/execute [(dyn :executable) "-e" (string "(os/sleep " n ")")])
|
||||
(os/execute [(dyn :executable) "-e" (string "(os/sleep " n ")")] :p)
|
||||
(print name " finished work!"))
|
||||
|
||||
# Will be done in parallel
|
||||
|
@ -76,9 +76,16 @@ void num_array_put(void *p, Janet key, Janet value) {
|
||||
}
|
||||
}
|
||||
|
||||
static Janet num_array_length(int32_t argc, Janet *argv) {
|
||||
janet_fixarity(argc, 1);
|
||||
num_array *array = (num_array *)janet_getabstract(argv, 0, &num_array_type);
|
||||
return janet_wrap_number(array->size);
|
||||
}
|
||||
|
||||
static const JanetMethod methods[] = {
|
||||
{"scale", num_array_scale},
|
||||
{"sum", num_array_sum},
|
||||
{"length", num_array_length},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -109,6 +116,11 @@ static const JanetReg cfuns[] = {
|
||||
"(numarray/scale numarray factor)\n\n"
|
||||
"scale numarray by factor"
|
||||
},
|
||||
{
|
||||
"sum", num_array_sum,
|
||||
"(numarray/sum numarray)\n\n"
|
||||
"sums numarray"
|
||||
},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
(import build/numarray)
|
||||
(import /build/numarray)
|
||||
|
||||
(def a (numarray/new 30))
|
||||
(print (get a 20))
|
||||
|
@ -532,16 +532,19 @@
|
||||
|
||||
(defmacro loop
|
||||
```
|
||||
A general purpose loop macro. This macro is similar to the Common Lisp
|
||||
loop macro, although intentionally much smaller in scope.
|
||||
The head of the loop should be a tuple that contains a sequence of
|
||||
either bindings or conditionals. A binding is a sequence of three values
|
||||
that define something to loop over. They are formatted like:
|
||||
A general purpose loop macro. This macro is similar to the Common Lisp loop
|
||||
macro, although intentionally much smaller in scope. The head of the loop
|
||||
should be a tuple that contains a sequence of either bindings or
|
||||
conditionals. A binding is a sequence of three values that define something
|
||||
to loop over. Bindings are written in the format:
|
||||
|
||||
binding :verb object/expression
|
||||
|
||||
Where `binding` is a binding as passed to def, `:verb` is one of a set of
|
||||
keywords, and `object` is any expression. The available verbs are:
|
||||
where `binding` is a binding as passed to def, `:verb` is one of a set of
|
||||
keywords, and `object` is any expression. Each subsequent binding creates a
|
||||
nested loop within the loop created by the previous binding.
|
||||
|
||||
The available verbs are:
|
||||
|
||||
* `:iterate` - repeatedly evaluate and bind to the expression while it is
|
||||
truthy.
|
||||
@ -565,14 +568,19 @@
|
||||
where `:modifier` is one of a set of keywords, and `argument` is keyword-dependent.
|
||||
`:modifier` can be one of:
|
||||
|
||||
* `:while expression` - breaks from the loop if `expression` is falsey.
|
||||
* `:until expression` - breaks from the loop if `expression` is truthy.
|
||||
* `:let bindings` - defines bindings inside the loop as passed to the `let` macro.
|
||||
* `:before form` - evaluates a form for a side effect before the next inner loop.
|
||||
* `:after form` - same as `:before`, but the side effect happens after the next inner loop.
|
||||
* `:while expression` - breaks from the current loop if `expression` is
|
||||
falsey.
|
||||
* `:until expression` - breaks from the current loop if `expression` is
|
||||
truthy.
|
||||
* `:let bindings` - defines bindings inside the current loop as passed to the
|
||||
`let` macro.
|
||||
* `:before form` - evaluates a form for a side effect before the next inner
|
||||
loop.
|
||||
* `:after form` - same as `:before`, but the side effect happens after the
|
||||
next inner loop.
|
||||
* `:repeat n` - repeats the next inner loop `n` times.
|
||||
lets try putting a loop item on multiple lines.
|
||||
* `:when condition` - only evaluates the loop body when condition is true.
|
||||
* `:when condition` - only evaluates the current loop body when `condition`
|
||||
is true.
|
||||
|
||||
The `loop` macro always evaluates to nil.
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user