Group Abstract Group Abstract

Message Boards Message Boards

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

[?] Evaluate the following function f[x__Integer]:=x[[2]]; f[{7,8}]?

Attachments:
POSTED BY: Ulrich Mutze
2 Replies

Neil,

Thank you very much for your perfect answer.

And, also the Mathematica Book speaks of sequences and not of lists, in accordance with your answer.

Regards,

Ulrich

POSTED BY: Ulrich Mutze

Ulrich,

Your list of integers has Head of List, not Head of Integer so your function does not match a list of integers. Your definition should look like this:

f[{x__Integer}] := {x}[[2]]

or (a bit more cryptically:

f[{x__Integer}] :=  ##2 &[x]

The reason is that you have a list of integers which you can match with

{x__Integer}

x will take on the value of a Sequence of Integers (not a list). Since it is a sequence and not a list you can either make it a list by doing {x} and then process it. or you can treat it as a sequence (second example).

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