Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.7K Views
|
6 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Individually apply functions in a list to the same arguments,& list results

Anonymous User
Anonymous User
Posted 7 years ago

This does what I want:

In[688]:= #[x] & /@ {f, g}

Out[688]= {f[x], g[x]}

but is there a better way, maybe a native function particularly for this purpose? Or some pattern tricks I haven't thought of?

POSTED BY: Anonymous User
6 Replies

Joe,

Michael has a great point. (That happens to be the way I discovered Through a while back when I had a bunch of variable names and I had to make them all a function of time, t). The "See Also" is invaluable. Also, the "tutorials" and "related Guides" are really good places to go once you get close. I agree that the Language has many, many commands and it is really hard to remember them especially if you do not use them regularly. Every few weeks I pick up a new command or a new use of a command by reading these forums. There are usually many ways to do the same thing (as you pointed out).

Regards,

Neil

POSTED BY: Neil Singer
Anonymous User
Anonymous User
Posted 7 years ago

I have an easier time searching and finding in Unix info and emacs-info, and I'm no unix expert. I regularly browse the "See Also" function-list at the bottom, but in this case the word 'Through' had looked unlikely in my wrong estimation. When you're traversing a massive graph, you can't click every hyperlink link.

Has anyone made an ordered tree (i.e., a structure like a conventional table of contents) of all the tutorials? An ordered table-of-contents to the tutorials that could be browsed from beginning to end? Books provide one, and Unix info does too, and I guess it helps me to associate various topics with various areas in the physical appearance of the ordered TOC as I'm getting familiar with a technical book. Getting to know a 2D image with a peculiar shape might be easier than navigating a graph with who knows what topology.

Unix info allows me to navigate without taking my hands off the keyboard, more efficient and less stressful because my mouse stresses me.

POSTED BY: Anonymous User

...could not find it in the docs for the life of me, over many weeks.

Hi Joe, Please allow me to share how I use docs when learning a new system (I learned Unix in a similar way thirty-odd years ago when we sometimes would to have to wait 0.5-1.0 hr for a free terminal to use the mainframe). Toward the bottom of the doc page for a command, there is a "See Also" section. Generally, these are commands that are related in some way.

So for instance, you found Map already, since you used it in the question. I might think to myself, "Gee, f /@ {a, b, c} === {f[a], f[b], f[c]} is like what I want but with roles of the functions and arguments switched. What I really want is something like {f, g, h} @/ x === {f[x], g[x], h[x]}. I wonder if there is such a thing?"

So I would look up Map and explore what's related. There are admittedly for Map quite a few commands to explore, but Through is on the list. (If I had thought that what I wanted was kind of like Apply, a word in the question title, I would have had a shorter list to explore.) Still, if I had the patience to stick to it, I would probably have seen the first example in the docs for Through, which shows exactly what I wanted above. In any case, I think it would have taken less than weeks, plus I probably would have learned about a few other functions on the See-Also list.

POSTED BY: Michael Rogers
Anonymous User
Anonymous User
Posted 7 years ago

Thank you.

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 7 years ago

I had a hunch there was a tool for the job, but could not find it in the docs for the life of me, over many weeks. That idiom has been getting me by though. Thanks again, Neil.

POSTED BY: Anonymous User
Through[{Cos, Sin}[radians]]

Regards,

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard