[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Suggestion of new program: execute mathematical set operations on lists



Hi Frank,

I think I know a language that will do what you want, it is called
LISP! Lisp stands for `list processing language' or `lots of
irritating superfluous parentheses' when it doesn't. Lisp allows you
to program as if you were writing mathematics, aka functional
programming.

I learned Lisp from the 1986 6.001 lectures
<https://www.youtube.com/watch?v=2Op3QLzMgSY&list=PL8FE88AA54363BC46>.
The dialect of Lisp I am using is called Scheme and the implementation
I am using is called Guile
<https://packages.debian.org/sid/guile-2.0>.

For examples on doing sets operations on list, see
<http://srfi.schemers.org/srfi-1/srfi-1.html#SetOperationsOnLists>,
but you would need to know basic Scheme first. (Just watch the 6.001
lectures, they should blow your mind if you haven't seen Lisp before!)

Examples:
(lset-union eq? '(a b c d e) '(a e i o u))
=> (u o i a b c d e)
(lset<= eq? '(a) '(a b a) '(a b c c))
=> #t

Explanations:
Q: What is the union of (a b c d e) and (a e i o u)
A: (u o i a b c d e)
Q: Is (a) a subset of (a b a) and (a b a) a subset of (a b c c)?
A: True

Cheers,
Alex

2015-09-26 0:11 GMT+08:00, Frank Stähr <der-storch-85@gmx.net>:
> Hello everybody,
>
> I am not yet looking for a sponsor, but going to program a tiny tool:
>
> "setop" takes as inputs several lists/sets, calculates desired
> (mathematical) set operations on them and outputs the final set (or
> depending on operation resulting number of elements, answer yes/no, …).
>
> For example: File A contains 3 3 2 5 1 (each number an extra line). Then
> setop A
> would result in 1 2 3 5. This is equivalent to
> sort | uniq
>
> With a file B containing 5 90 2 7 the command
> setop -i A B
> would yield 2 5.
>
> Here, -i stands for intersection. Of course, there is no limitation to
> numbers, elements can be any non-empty strings. Other operations are
> union, symmetric difference, difference, contains element, is subset,
> cardinality and so on.
> Is this tool senseful, is there a certain need for it?
>
> As you can see on
> <http://www.catonmat.net/blog/set-operations-in-unix-shell-simplified/>
> nearly all these operations can already be done with other tools, but
> the according command lines are mostly very tortuous. There doesn’t seem
> to be a tool that directly works with sets.
>
> So my questions is: Is there a need for such a program or is there
> already something very similar? (Is this the right place for asking?)
> I even exactly know what options setop should have and what it can do
> (how it is used), but am waiting for some responses from you before
> programming.
>
> Note: I already asked two years ago but didn’t get satisfactory
> responses. Only now I remembered my idea.
>
> I would be very grateful for your feedback,
> Frank
>
>


Reply to: