0
|
5811 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

# A better way to supply the elements of a list as arguments to a function ..

Posted 10 years ago
 The built-in function BooleanFunction creates a function that accepts a specified number of arguments. There's some way(?), that is escaping me, to convert the elements of a list into a sequence of arguments. Here's an example (and attached), using #[[1]] and #[[2]] to extract the elements of a list of length 2 ... Create boolean function #1, of two variables ... f = BooleanFunction[1, 2] Display the function ... BooleanConvert[f[x, y], "DNF"] ! x && ! y Confirm on one pair of values ... f[False, False] True Generate all boolean pairs ... Tuples[{False, True}, 2] {{False, False}, {False, True}, {True, False}, {True, True}} Apply function to each pair using ugly method ... f[#[[1]], #[[2]]] & /@ % {True, False, False, False} Attachments:
2 Replies
Sort By:
Posted 10 years ago
 Yes, thank you!Sequence @@Is what I was trying to remember; I forgot it was a two-step thing - replace the head of the list with Sequence and then execute Sequence.Couldn't get there using Help.-- Mark
Posted 10 years ago
 Could define a transition function that explicitly makes the list into a sequence. f = BooleanFunction[1, 2]; tt = Tuples[{False, True}, 2]; f[#[[1]], #[[2]]] & /@ tt g[ll_List] := f[Sequence @@ ll] g /@ tt {True, False, False, False} {True, False, False, False} {True, False, False, False} 
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments