Re: returning multiple values vs a list

From: Paul F. Dietz (dietz_at_dls.net)
Date: 10/28/04


Date: Wed, 27 Oct 2004 20:39:03 -0500
To: Peter Seibel <peter@javamonkey.com>

Peter Seibel wrote:
> Suppose I'm writing a function to take apart a list into a few pieces.
> I can write it to return multiple values and let callers use
> MULTIPLE-VALUE-BIND to grab the individual parts. Or I can write it to
> return a list and let callers use DESTRUCTURING-BIND. Any reason to
> prefer one or the other? Suppose for the sake of argument that
> everywhere I use it I use all the values; obviously if I sometimes
> wanted only the primary value then multiple values would be the way to
> go.

Multiple values can be implemented without heap allocation;
that's harder to do for a list.

Another thing you could do is allocate a simple vector in the caller,
pass the simple vector to the function, and have the function fill in
the vector. If the vector is declared dynamic extent it can be heap
allocated. Wrap with suitable macros to hide the details.

        Paul



Relevant Pages

  • Re: what ML language do you recommend?
    ... >>>I think the definition of realtime is just that the gc never imposes ... >allocation patterns that are less dynamic and would benefit from GC ... working with multiple mutators and it never performed well enough IMO ... > systems with relatively long deadlines ...
    (comp.lang.functional)
  • Re: How to use Delete in right way
    ... > in which case you should get an access violation at the time of ... If the allocation goes through CRT malloc/new/etc, ... granularity of 16 bytes hides these problems from PageHeap completely, ... unless the length of the block is multiple of 16. ...
    (microsoft.public.vc.debugger)
  • Re: how much does free free?
    ... Free does not free the same amount of memory as the size of the malloc ... free must release a multiple of 4 or 8 ... might ask this question is to find out what the system overhead ... allocated by the call to an allocation function, calloc, ...
    (comp.lang.c)
  • [PATCH 0/4, v14] PCI, ACPI: Physical PCI slot objects
    ... API, pci_update_slot_number, which can be used by callers to ... this patch series slightly changes the logic introduced ... the check against registering a slot with the ... scenario where multiple pcihp drivers try to claim the same slot. ...
    (Linux-Kernel)
  • Re: What gives you power in CL, that you dont have in other languages
    ... All modern FPLs may be considered as very advanced extensions to Lisp. ... Your "tuple" incurs costly heap allocation when it is created and bounds ... Multiple values don't occur heap allocation. ... Push and pop are thought of as destructive (this is cross-posted to ...
    (comp.lang.lisp)