Skip to content

Commit

Permalink
removed deprecated labels from elementAt and reducer functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Dec 24, 2024
1 parent 3fb9b23 commit ab9b274
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
21 changes: 19 additions & 2 deletions src/org/rascalmpl/library/List.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,17 @@ dup([3, 1, 5, 3, 1, 7, 1, 2]);
list[&T] dup(list[&T] lst)
= ([] | (ix in it) ? it : it + [ix] | &T ix <- lst);

@deprecated{Use a list index instead}
@javaClass{org.rascalmpl.library.Prelude}
@synopsis{A function that implements `lst[index]`}
@description{
The expression `lst[index]` has the same semantics as calling `elementAt(index)`.
}
@benefits{
* ((elementAt)) can be passed a function argument.
}
@pitfalls{
* `lst[index]` is significantly faster than `elementAt(index)`
}
java &T elementAt(list[&T] lst, int index);


Expand Down Expand Up @@ -480,9 +489,10 @@ list[&T] push(&T elem, list[&T] lst) = [elem] + lst;
@synopsis{Apply a function to successive elements of list and combine the results.}
@deprecated{This function is deprecated. Use a reducer expression instead, like `(init | f(it, e) | e <- lst)`.}
@description{
Apply the function `fn` to successive elements of list `lst` starting with `unit`.
The function application `reducer(lst, add, 0)` has the same semantics
as the expression `(0 | add(it, e) | e <- lst)`.
}
@examples{
```rascal-shell
Expand All @@ -491,6 +501,13 @@ int add(int x, int y) { return x + y; }
reducer([10, 20, 30, 40], add, 0);
```
}
@benefits{
* reducer can be passed as a function argument
}
@pitfalls{
* a reducer expression can be a lot faster
* reducer expressions are more versatile (allowing multiple generators and filters)
}
&T reducer(list[&T] lst, &T (&T, &T) fn, &T unit) = (unit | fn(it, elm) | elm <- lst);
list[&T] remove(list[&T] lst, int indexToDelete) =
Expand Down
20 changes: 0 additions & 20 deletions src/org/rascalmpl/library/lang/json/internal/JsonValueReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.rascalmpl.debug.IRascalMonitor;
import org.rascalmpl.exceptions.RuntimeExceptionFactory;
Expand Down Expand Up @@ -698,25 +697,6 @@ public IValue visitConstructor(Type type) throws IOException {
return read(in, type.getAbstractDataType());
}

private boolean isJavaIdentifier(String s) {
if (s.isEmpty()) {
return false;
}
else {
if (s.charAt(0) != '_' && !Character.isJavaIdentifierStart(s.charAt(0))) {
return false;
}

for (int i = 1; i < s.length(); i++) {
if (!Character.isJavaIdentifierPart(i)) {
return false;
}
}
}

return true;
}

@Override
public IValue visitNode(Type type) throws IOException {
if (isNull()) {
Expand Down

0 comments on commit ab9b274

Please sign in to comment.