Mozart/Oz: how to make record with Record.make - record

I am trying to create a record from list using Record.make:
declare
L=[z [a b] [1 2]]
{Record.make L.1 L.2 0}
but getting an error:
Expected type: feature
At argument: 1
How to make a second argument L.2 to be A 'feature' type? I assume L.2 is a [a b] list.

Record.make creates a record with fresh (i.e. unbound) values. For example:
R = {Record.make label [a b]}
Maybe you want List.toRecord instead:
R = {List.toRecord label [a#1 b#2]}

Related

How can I join sets in Zimpl?

I have two parameters read from file, of m*n (Months * Nights) dimension:
A[m,n] and B[m,n]
How can I make a set / parameter from these two parameters so that the new set will have the same indices m*n, and elements combined as sets with an extra zero between?
For example, let's say A["D", 5] = 35, B["D", 5] = 2 ,
I want to have C["D", 5] = {35, 0, 2}
Is this possible?
ps: I want to use it in the objective min/max, I tried to just use
{A[a,b], 0, B[a,b]}[index]
but failed, so I am trying to get a pre-defined sets to use instead.
I managed to do it like this:
set C[<m,n> in Months*Nights] := {A[m,n], 0, B[m,n]} ;
And I can refer them in this way:
ord(C[m,n],3,1)
Where 3 refer to B[m,n], and 1 is a placeholder for the third parameter of ord function.

Value of local variables in a function seems not be released post function calling in Red/Rebol language

I construct a function named find-all to find all indexes of a given item in a series by "recursive".
The first calling of find-all gives the right output. However from the second calling, all outputs are appended together.
find-all: function [series found][
result: []
either any [empty? series none? s-found: find series found]
[result]
[append result index? s-found
find-all next s-found found]
]
;; test:
probe find-all "abcbd" "b" ;; output [2 4] as expected
probe find-all [1 2 3 2 1] 2 ;; output [2 4 2 4]
Since variables inside a function created with function are local, why does the value of variable result is still there during later funtion callings, which cause the result of the sencond calling of find-all does not begin with []?
And what is the correct recursive way to achieve this funciton?
The answer is evident if you inspect find-all after making these two calls:
>> ?? find-all
find-all: func [series found /local result s-found][
result: [2 4 2 4]
either any [empty? series none? s-found: find series found]
[result]
[append result index? s-found
find-all next s-found found
]
]
result is an indirect value, and its data buffer is stored on a heap. The data gets preserved between the calls and accumulated, because you do not re-create it with copy — result being local to function's context is unrelated to that.
Thanks to #9214's help, especially the description about indirect value. I give a solution like this:
find-all: function [series found][
either any [empty? series none? s-found: find series found]
[[]]
[append
reduce [index? s-found]
find-all next s-found found
]
]
;; test:
probe find-all "abcbd" "b" ;; output [2 4] as expected
probe find-all [1 2 3 2 1] 2 ;; output [2 4] as expected

adding element to series with simple '.' notation

x = pd.Series()
x.a = 1
x.a
>> 1
x.values()
>> array([])
x.a can be retrieved by calling it directly (x.a) but selecting a list of series elements doesn't include 'a'.
Is there a way to get a list of elements that does include 'a'.
This is not way to assign a new value by using .
x.loc['a']=1
x
Out[53]:
a 1
dtype: int64

Karate API - How we can get the specific array element for which index will be dynamic. I need value for last array element which is not fixed

I read that variable will not work as a index in array when we try to access array[i] or something like that.
so How I can or get a value for last element of the array which is dynamic. It will change after every API call.
Variables will work in JS. They won't work in JsonPath (e.g. match Left Hand Side), read the docs to understand the difference:
* def foo = [1, 2, 3, 4]
* def size = karate.sizeOf(foo)
* def last = foo[size - 1]
* match last == 4

Most elegant way to extract block by skipping every 2 element

Let's say I have
block: [a 1 b 2 c 3]
I want
[1 2 3]
Something like this is clunky and it doesn't work because I use word type (I'd like to have it word with word not string):
block: [a 1 b 2 c 3]
block2: []
counter: -1
foreach 'element block [
counter: negate counter
if counter append block2 element
]
The EXTRACT function should fit the bill here:
>> extract/index [a 1 b 2 c 3] 2 2
== [1 2 3]
It's fairly versatile for this type of thing.
>> help extract
USAGE:
EXTRACT series width
DESCRIPTION:
Extracts a value from a series at regular intervals.
EXTRACT is a function! value.
ARGUMENTS:
series [series!]
width [integer!] "Size of each entry (the skip)".
REFINEMENTS:
/index => Extract from an offset position.
pos [integer!] "The position".
/into => Provide an output series instead of creating a new one.
output [series!] "Output series".