YailList add

136 views
Skip to first unread message

Red Panda

unread,
Jun 28, 2018, 10:57:42 AM6/28/18
to App Inventor Open Source Development
I'm still not sure if I understood the differences between run-time and compile-time correctly, but I ask myself why there isn't an easy add function of the YailList class. It exists in the Documentation, but I can't use it in my components. Maybe somebody can explain.

- Red Panda

Mark Friedman

unread,
Jun 29, 2018, 4:33:49 PM6/29/18
to app-inventor-o...@googlegroups.com
It appears that the documentation you are looking at is for a version of the App Inventor Java Bridge, not App Inventor itself.  That version of the Java Bridge has a different implementation of YailList than the one that App Inventor uses.

-Mark

On Thu, Jun 28, 2018 at 7:57 AM Red Panda <redpan...@gmail.com> wrote:
I'm still not sure if I understood the differences between run-time and compile-time correctly, but I ask myself why there isn't an easy add function of the YailList class. It exists in the Documentation, but I can't use it in my components. Maybe somebody can explain.

- Red Panda

--
You received this message because you are subscribed to the Google Groups "App Inventor Open Source Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-open-so...@googlegroups.com.
To post to this group, send email to app-inventor-o...@googlegroups.com.
Visit this group at https://groups.google.com/group/app-inventor-open-source-dev.
For more options, visit https://groups.google.com/d/optout.

Evan Patton

unread,
Jun 29, 2018, 5:18:36 PM6/29/18
to App Inventor Open Source Development
In App Inventor, YailList is a specialization of Kawa Scheme's Pair class. Thus, all lists in App Inventor are singly linked lists. The add(Object) method you call is defined by AbstractSequence, and assumes that there is a method called addPos(int, Object) implemented. This is true of Kawa Scheme's Vector classes, but not of Pair. The primary reason for this is that you can't make assumptions about what a Pair represents (it could be used to construct a tree as opposed to a list, or could be the terminator of a dotted list). Because of the computational properties of singly linked lists, expect that add(Object) will need O(n) time to perform an insertion. There are a few ways you could go about addressing the problem:

1. Implement a helper function (won't require changes to core App Inventor), that calls lastPair() to get the last pair and then calls setCdr() with a new list constructed with LList.makeList(Object[]). You could use a similar strategy both for add and addAll (the latter of which is important because the naive implementation will result in O(n^2) complexity).
2. Implement addPos(int, Object) on YailList, since we have stronger semantics there about how the object is being manipulated.
3. Implement add(Object) and addAll(Collection) functions on YailList, overriding the superclass implementations.
4. More hacky version of 2/3 but doesn't require changing YailList: Create a SmartYailList class that extends YailList and, given a YailList, "wraps" it. Have it implement add(Object) and addAll(Collection), and use it to wrap/manipulate YailLists. Since every SmartYailList is a YailList, you should be able to use it wherever a YailList is required.

Cheers,
Evan

Evan Patton

unread,
Jun 29, 2018, 5:20:37 PM6/29/18
to App Inventor Open Source Development
I should point out that option 4 breaks if there are places we use eq? to check identity rather than using equal? for equality, since the new list will not the same as the old.

Evan

Red Panda

unread,
Jul 5, 2018, 6:03:12 AM7/5/18
to App Inventor Open Source Development
Thanks for clearing this up Mark.

-Red Panda

Am Freitag, 29. Juni 2018 22:33:49 UTC+2 schrieb Mark Friedman:
It appears that the documentation you are looking at is for a version of the App Inventor Java Bridge, not App Inventor itself.  That version of the Java Bridge has a different implementation of YailList than the one that App Inventor uses.

-Mark

On Thu, Jun 28, 2018 at 7:57 AM Red Panda <redpan...@gmail.com> wrote:
I'm still not sure if I understood the differences between run-time and compile-time correctly, but I ask myself why there isn't an easy add function of the YailList class. It exists in the Documentation, but I can't use it in my components. Maybe somebody can explain.

- Red Panda

--
You received this message because you are subscribed to the Google Groups "App Inventor Open Source Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-open-source-dev+unsub...@googlegroups.com.

Red Panda

unread,
Jul 5, 2018, 6:05:29 AM7/5/18
to App Inventor Open Source Development
Thanks for the detailed information Evan. I will take a look at this. And thanks for the tip with the O(n^2) runtime

-Red Panda
Reply all
Reply to author
Forward
0 new messages