Ask Your Question
1

Which library functions are missing from Rascal?

asked Nov 08 '11

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated Dec 20 '11

DavyLandman gravatar image DavyLandman flag of Netherlands
267 4 17
http://homepages.cwi.nl/~...

We want to improve the Rascal libraries. Therefore we love to hear from you which library functions you are missing.

Thank you for helping us to make Rascal a great language.

delete close flag offensive retag edit

7 Answers

Sort by ยป oldest newest most voted
0

answered Jan 13

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated Jan 13

Hossein gravatar image Hossein
81 8 20

Here is another function I would add to list library this time: (another overload of the slice function)

list[&T] slice(list[&T] lst, int begin)

where the result is lst from begin onwards.

link delete flag offensive edit
0

answered Dec 15 '11

Hossein gravatar image Hossein
81 8 20

updated Dec 20 '11

Here are few minor features:

  1. For str objects, we need something like pop_back(n) which will remove the n trailing characters of the string. n should obviously default to one.
  2. For map, we need a function like remove_key(k) which removes the key k (and its respective value), if any. The current syntax, as far as I could dig it, is just so clumsy: m - (k: v), with arbitrary value v of the range type of m. If no such value exists, one needs to coin a random one! Not in every context this makes sense.

  3. We need good wildcard support! We currently lack support for many reasonable usecases. Here is a very simple and pervasive example: m - (k: _).

link delete flag offensive edit

Comments

1

Something like remove_key would be a nice specialization to add to the library. Currently you can say k = domainX(m,{k}) to get the same effect (rangeX does the same, but for the range of the map). This takes care of the case you mention without needing to invent a value.

MarkHills (Jan 16)edit

Yes, I have to confess that I hadn't taken domainX into consideration. That clearly does the job, with remove_key only being a specialisation for a single element removal -- as you mentioned. Thanks!

Hossein (Jan 20)edit

Oops, m = domainX(m,{k}) -- I may as well have a comment without a type error :)

MarkHills (Jan 22)edit
0

answered Nov 08 '11

Radu Mereuta gravatar image Radu Mereuta
96 6

Working with SDF and Rascal, I found that I is much easier to design the grammar in SDF, because you can see the AST in a simple and compact form. Even if it is text, I could easily see that I forgot to put some follow restrictions or that some rules are ambiguous. I know that there are some functions that can allow you to see the parse tree in a compact way, but I couldn't make it to work, and I've seen that others had problems with it when they had ambiguities.

Also, can you have generic term composition and decomposition in the ParseTree and ADT?

link delete flag offensive edit

Comments

By compact form you mean imploded prefix form, right?

JurgenVinju (Nov 08 '11)edit

Yes. I told Mark about this during the K workshop this summer and he told me that it could easily be done, and he actually started working on something like that, but didn't make it in this release. Maybe the next one.

Radu Mereuta (Nov 08 '11)edit

what happens if you call the implode function from ParseTree.rsc with #node as a type?

JurgenVinju (Nov 08 '11)edit

Jurgen, at least if there is an ambiguity, this yields an IllegalArgument exception. Since they specifically want to see and resolve ambiguities, this won't work, at least in it's current form.

MarkHills (Nov 09 '11)edit

Ok thanks!

JurgenVinju (Nov 10 '11)edit
0

answered Dec 20 '11

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated Dec 20 '11

Dennisb gravatar image Dennisb
1 2 2
  • A sum function for map, set, list etc;
  • Simplify casting from value;
  • A rounding function;
  • Improvement of escape function, now you have to map all types of encoding;

These functions were important for outputting Series 1&2.

link delete flag offensive edit
0

answered Dec 16 '11

Hossein gravatar image Hossein
81 8 20

Here is another very minor one: writelnFile which is the file counterpart of println.

link delete flag offensive edit

Comments

No, writeFile doesn't do the job for it doesn't put the \n in. I do know that's trivial to implement. But, println is also trivial to implement above print. Yet, almost every language provides it for its ubiquity of use.

Hossein (Dec 20 '11)edit
0

answered Jan 24

JasperT gravatar image JasperT
33 1 5 11

updated Jan 24

simple one: a join function on a list[str] and set[str] with a string of choice as glue. Thanks to Arjen:

import Set;
public str joinstr(list[str] L, str glue) = ("" | size(it) > 0 ? "<it><glue><e>" : "<e>" | str e <- L);
public str joinstr(set[str] S, str glue) = joinstr(toList(S), glue);
link delete flag offensive edit

Comments

1

Ah, we missed it! Maybe because of the name? Thanks again.

JasperT (Jan 24)edit
0

answered Jan 16

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated Jan 24

Hossein gravatar image Hossein
81 8 20

I cannot possibly help cursing Rascal for forcing me to write:

r.js = (r.js - (j: <j_name, false>)) + (j: <j_name, true>);

instead of

r.js[j][1] = true;

Full stop!!!

I wish I had also documented the error message that I got for it now works. But, it was something like "Internal Exception: ... not implemented yet" which made me sure that that's a problem with Rascal's current implementation.

link delete flag offensive edit

Comments

Can you give a more complete example? I can write that, and it works, but I don't know your entire context.

MarkHills (Jan 16)edit

As a matter of fact, I have just double-checked it and it no longer sniggers at me. For the record though, I'll update my original post on the matter with the full relevant contents.

Hossein (Jan 20)edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]
Also see the Rascal Tutor.

Question tools

Follow

subscribe to rss feed

Stats

Asked: Nov 08 '11

Seen: 90 times

Last updated: Jan 24

Related questions