[Wrapl-discussion] list:delete, list:remove
Brought to you by:
rajamukherji
|
From: Roman M. <rom...@gm...> - 2010-09-02 09:43:18
|
Raja, Do you think it is practical to return the removed value from list:delete and list:remove methods? I mean, instead of returning the remaining list. Perhaps, you have already wrote some working code that uses these methods that way. What are your reasons? My thoughts: -------------------------------------------------------------------------------- :copy, :empty, :insert, :reverse, :shift, :sort - all return the modified list. Why :delete and :remove should return the value? :pop, :pull, :push, :put - are stack-style methods - they shouldn't be a pattern. In case of list:remove the value to be removed is already known to be returned. As an example: -------------------------------------------------------------------------------- If :delete returns a list, this programming challenge: http://www.reddit.com/r/programming/comments/2xdkd/google_interview_questions/c2xe85 could be solved in one line: TO :puzzle(list @ List.T) ALL :"*":foldl(ALL list:copy:delete(list:keys)); -- or TO :puzzle(list @ List.T) ALL PROD list:copy:delete(list:keys):values; [1, 2, 3, 4, 5]:puzzle; By the way, there is a typo in :shift description: -------------------------------------------------------------------------------- :shift(list @ T, n @ Std.Integer.SmallT, r @ Std.Integer.SmallT) : T shifts the nth element by n positions within list -> shifts the nth element by r positions within list -- Roman |