Skip to content

Commit 0348d42

Browse files
committed
bug(objectionary#3481): tuple value and prev
1 parent 983b3c9 commit 0348d42

File tree

7 files changed

+115
-118
lines changed

7 files changed

+115
-118
lines changed

eo-runtime/src/main/eo/org/eolang/fs/dir.eo

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@
7878
^.len.eq index
7979
true
8080
seq *
81-
tup.tail.deleted.exists
81+
tup.value.deleted.exists
8282
^.rec-delete
83-
tup.head
83+
tup.prev
8484
index.plus 1
8585

8686
# Creates an empty temporary file in the current directory.

eo-runtime/src/main/eo/org/eolang/fs/path.eo

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
if.
108108
and.
109109
accum.length.gt 0
110-
(accum.tail.eq "..").not
111-
accum.head
110+
(accum.value.eq "..").not
111+
accum.prev
112112
if.
113113
^.is-absolute.not
114114
accum.with segment
@@ -362,8 +362,8 @@
362362
if.
363363
and.
364364
accum.length.gt 0
365-
(accum.tail.eq "..").not
366-
accum.head
365+
(accum.value.eq "..").not
366+
accum.prev
367367
if.
368368
and.
369369
^.is-root-relative.not

eo-runtime/src/main/eo/org/eolang/seq.eo

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
true
3535
if.
3636
steps.length.eq 1
37-
steps.tail
37+
steps.value
3838
loop steps
3939
steps.length.plus -1 > last-index!
4040

@@ -46,8 +46,8 @@
4646
if. > @
4747
and.
4848
tup.length.gt 1
49-
loop tup.head
50-
tup.tail
49+
loop tup.prev
50+
tup.value
5151
or.
52-
(dataized tup.tail).as-bool.eq --
52+
(dataized tup.value).as-bool.eq --
5353
tup.length.eq last-index

eo-runtime/src/main/eo/org/eolang/structs/list.eo

+58-67
Original file line numberDiff line numberDiff line change
@@ -53,93 +53,90 @@
5353
# The first one for the accumulator, the second one
5454
# for the element of the collection and the third one for the index.
5555
[start func] > reducedi
56-
^.origin.length > origin-len!
5756
if. > @
58-
0.eq origin-len
57+
is-empty
5958
start
60-
rec-reduced start 0.as-bytes
59+
rec-reducedi origin
6160

62-
[accum index] > rec-reduced
63-
index.as-number > idx-as-number
64-
1.plus idx-as-number > next-index!
61+
[tup] > rec-reducedi
6562
if. > @
66-
next-index.eq ^.origin-len
67-
^.func > accumulated
68-
accum
69-
^.^.origin.at idx-as-number
70-
idx-as-number
71-
^.rec-reduced
72-
accumulated
73-
next-index
63+
tup.length.eq 1
64+
func
65+
start
66+
tup.value
67+
0
68+
func
69+
rec-reducedi tup.prev
70+
tup.value
71+
tup.prev.length
7472

7573
# Reduce from "start" using the function "func".
7674
# Here "func" must be an abstract object with two free attributes.
7775
# The first one for the accumulator, the second one for the element
7876
# of the collection.
7977
[start func] > reduced
80-
^.reducedi > @
78+
reducedi > @
8179
start
82-
^.func accum item > [accum item idx] >>
80+
func accum item > [accum item idx] >>
8381

8482
# Map with index. Here "func" must be an abstract
8583
# object with two free attributes. The first
8684
# one for the element of the collection, the second one
8785
# for the index.
8886
[func] > mappedi
8987
list > @
90-
^.reducedi
88+
reducedi
9189
*
9290
[accum item idx] >>
93-
with. > @
94-
accum
95-
^.func item idx
91+
accum.with > @
92+
func item idx
9693

9794
# Map without index. Here "func" must be an abstract
9895
# object with one free attribute, for the element
9996
# of the collection.
10097
[func] > mapped
101-
^.mappedi > @
102-
^.func item > [item idx] >>
98+
mappedi > @
99+
func item > [item idx] >>
103100

104101
# For each collection element dataize the object
105102
# Here "func" must be an abstract object with
106103
# two free attributes: the element of the
107104
# collection and its index.
108105
# The result of `func` must be dataizable.
109106
[func] > eachi
110-
^.reducedi > @
107+
reducedi > @
111108
true
112109
[acc item index] >>
113110
seq * > @
114111
acc
115-
^.func item index
112+
func item index
116113

117114
# For each collection element dataize the object
118115
# Here "func" must be an abstract object with
119116
# one free attribute, the element of the collection.
120117
[func] > each
121-
^.eachi > @
122-
^.func item > [item index] >>
118+
eachi > @
119+
func item > [item index] >>
123120

124121
# Create a new list without the i-th element.
125122
[i] > withouti
126123
list > @
127-
^.reducedi
124+
reducedi
128125
*
129126
[accum item idx] >>
130127
if. > @
131-
^.i.eq idx
128+
i.eq idx
132129
accum
133130
accum.with item
134131

135132
# Create a new list without the `element` which is `.eq` to given one.
136133
[element] > without
137134
list > @
138-
^.reduced
135+
reduced
139136
*
140137
[accum item] >>
141138
if. > @
142-
^.element.eq item
139+
element.eq item
143140
accum
144141
accum.with item
145142

@@ -148,46 +145,45 @@
148145
[other] > eq
149146
and. > @
150147
eq.
151-
^.origin.length
148+
origin.length
152149
other.length
153-
^.reducedi
150+
rec-eq origin other
151+
152+
[first second] > rec-eq
153+
if. > @
154+
first.length.eq 0
154155
true
155-
[accum item idx] >>
156-
and. > @
157-
accum
158-
eq.
159-
item
160-
^.other.at idx
156+
and.
157+
first.value.eq second.value
158+
rec-eq first.prev second.prev
161159

162160
# Concatenates current list with given one.
163161
[passed] > concat
164-
reduced. > @
165-
list
166-
passed
162+
(list passed).reducedi > @
167163
^
168-
accum.with item > [accum item]
164+
accum.with item > [accum item index]
169165

170166
# Returns index of the first particular item in list.
171167
# If the list has no this item, index-of returns -1.
172168
[wanted] > index-of
173-
^.reducedi > @
169+
reducedi > @
174170
-1
175171
[accum item index] >>
176172
if. > @
177173
and.
178174
-1.eq accum
179-
item.eq ^.wanted
175+
item.eq wanted
180176
index
181177
accum
182178

183179
# Returns index of the last particular item in list.
184180
# If the list has no this item, returns -1.
185181
[wanted] > last-index-of
186-
^.reducedi > @
182+
reducedi > @
187183
-1
188184
[accum item index] >>
189185
if. > @
190-
item.eq ^.wanted
186+
item.eq wanted
191187
index
192188
accum
193189

@@ -197,7 +193,7 @@
197193
not. > @
198194
eq.
199195
-1
200-
^.index-of element
196+
index-of element
201197

202198
# Returns a new list sorted via `.lt` method.
203199
# @todo #3251:30min The object does not work. After moving `list` object
@@ -213,34 +209,29 @@
213209
# for the index. The result of dataization
214210
# the `func` should be boolean, that is `true` or `false`.
215211
[func] > filteredi
216-
^.origin.length > origin-length!
217212
list > @
218-
rec-filtered 0.as-bytes *
213+
rec-filteredi origin
219214

220-
[idx-as-bytes accum] > rec-filtered
221-
^.^.origin > original
222-
idx-as-bytes.as-number > index
223-
^.^.origin.at index > item
215+
[tup] > rec-filteredi
216+
rec-filteredi tup.prev > next
224217
if. > @
225-
idx-as-bytes.eq ^.origin-length
226-
accum
227-
^.rec-filtered
228-
(1.plus index).as-bytes
229-
if.
230-
^.func item index
231-
accum.with item
232-
accum
218+
tup.length.eq 0
219+
*
220+
if.
221+
func tup.value tup.prev.length
222+
next.with tup.value
223+
next
233224

234225
# Filter list without index with the function `func`.
235226
# Here `func` must be an abstract object
236227
# with one attribute for the element.
237228
# The result of dataization the `func`
238229
# should be boolean, that is `true` or `false`.
239230
[func] > filtered
240-
^.filteredi > @
241-
^.func item > [item index] >>
231+
filteredi > @
232+
func item > [item index] >>
242233

243-
# Get the first `index` elements from the start of the list.
234+
# Get the first `index` elements from the start of the list. todo
244235
[index] > head
245236
index > idx!
246237
switch > @
@@ -268,15 +259,15 @@
268259
# Get the last `index` elements from the end of the list.
269260
[index] > tail
270261
index > idx!
271-
^.origin.length.minus idx.as-number > start!
262+
origin.length.minus idx > start!
272263
if. > @
273264
0.gt start
274265
^
275266
list
276-
^.reducedi
267+
reducedi
277268
*
278269
[accum item idx] >>
279270
if. > @
280-
idx.gte ^.start
271+
idx.gte start
281272
accum.with item
282273
accum

eo-runtime/src/main/eo/org/eolang/tuple.eo

+9-8
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,24 @@
2727

2828
# Tuple.
2929
# An ordered, immutable collection of elements.
30-
[head tail length] > tuple
31-
$ > self
30+
[prev value length] > tuple
31+
$ > as-tuple
3232

3333
# Empty tuple.
3434
# A tuple with no elements. When dataized, it represents an immutable, empty collection.
3535
[] > empty
3636
$ > empty
37+
$ > as-tuple
3738
0 > length
38-
error "Can't get head from the empty tuple" > head
39-
error "Can't get tail from the empty tuple" > tail
39+
error "Can't get prev from the empty tuple" > prev
40+
error "Can't get value from the empty tuple" > value
4041

4142
# Take one element from the tuple, at the given position.
4243
error "Can't get an object from the empty tuple" > [i] > at
4344

4445
# Create a new tuple with this element added to the end of it.
4546
[x] > with
46-
self. > @
47+
as-tuple. > @
4748
tuple
4849
^
4950
x
@@ -66,12 +67,12 @@
6667
[tup] > at-fast
6768
if. > @
6869
(tup.length.plus -1).eq index
69-
tup.tail
70-
at-fast tup.head
70+
tup.value
71+
at-fast tup.prev
7172

7273
# Create a new tuple with this element added to the end of it.
7374
[x] > with
74-
self. > @
75+
as-tuple. > @
7576
tuple
7677
^
7778
x

0 commit comments

Comments
 (0)