Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Data Comparison Analysis

Name: Anonymous 2007-11-02 17:34

I have an to do a project that counts the number of comparisons made when searching an array of 1000 elements called list. One for binary search method and a hybrid method of searching. But that is beside the point. For simplicity and neatness I would like to contain everything into one method call. Maybe BinarySearch(list, target) and HybridSearch(list,target). The problem comes when I have to return both the number of comparisons made and the index of the target. I am sure there some ultra easy way to do this that I am not seeing.

Anyone?

Name: Anonymous 2007-11-02 20:57

>>9
In Common Lisp you can return a value (defun return-x (x) x) or you can return multiple values (defun return-all (x y z) (values x y z)). A caller will get only the first return value back, so it can treat the function as a single value or use (multiple-value-bind (first-value second-value whatever) (return-all 1 2 3) (format t "~A~A~A~%" first-value second-value whatever)) => 123.

Many standard library functions return multiple values, such as (truncate 1.4) => 1 and 0.39999998. Lol short floats. It's pretty handy.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List