[plt-scheme] append-map examples

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sat Apr 10 11:22:08 EDT 2010

Rules aren't hard and fast. BUT just in case you scale up, abstract over these things so that switching later on is easy. For example, in the FV example, you may wish to act as if you were using sets and use append-map underneath for a while until you know you need to do better. Then replace the implementation with trees. 




On Apr 10, 2010, at 11:07 AM, Todd O'Bryan wrote:

> Ack! I've been using append-map a lot recently. Granted, I then did
> something like remove-duplicates, usually, so I really had a set. But
> sometimes not. Here's the use case:
> 
> I'm representing SQL statements and have a function that returns a SQL
> string with parameter place-holders and a list of parameters,
> something like
> 
> (list "SELECT * FROM my_table WHERE id=?" (list 4))
> 
> except, of course, that the parts "*" and "id=?" could be literals. In
> other words, I could have
> 
> (list "SELECT ? FROM my_table WHERE id=?" (list "abc" 4))
> 
> I guess I could have created a structure with a sql-string and params
> part, but I'd still want to append-map the params together to keep
> them in the same order as the place-holders. So, is this a licit use
> of append-map, or have I strayed?
> 
> Todd
> 
> On Fri, Apr 9, 2010 at 10:49 PM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>> 
>> Dan Friedman once shared a rule with me: when you use append-map, you are using the wrong data representation.
>> 
>> Examples:
>> 
>> 
>> On Apr 9, 2010, at 10:40 PM, Ryan Culpepper wrote:
>> 
>>> Skeptic . wrote:
>>>> Hi,
>>>> Does someone knows canonical/pedagogical exemples of append-map except other than flatten ?
>>> 
>>> Collect a list of all the X in a Y.
>>> 
>>> eg, the list of free variables in a lambda term
>> 
>> Free variables come in sets, not lists.
>> 
>> 
>>> eg, the list of links in a web page (as xexpr or sxml)
>> 
>> Ditto.
>> 
>> 
>> _________________________________________________
>>  For list-related administrative tasks:
>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>> 



Posted on the users mailing list.