I'm really confused by the behavior of this function:

```
david[x_] := 5; 6; 7
david[]
```

returns

```
7
```

but `david[3]`

returns `5`

Why does this happen? I'd think the second case should also return 7; why doesn't it?

Surprisingly, the function is not misbehaving. In fact, its behavior is correct. After you defined the function david, you terminated it with a semi-colon, which was then followed by a constant (6), whose value is suppressed by the semi-colon, then a constant which is unsuppressed. Thus, when you try to evaluate the cell, the value of the function david is set to give 5, every time it is run:

```
david[x_] := 5; (* This is where the 5 comes from when you try to evaluate the cell*)
```

**The fact that you get 7 is because you have an unsuppressed constant.**

Compare to this:

```
david[x_] := 5; 6; 7; 9; 12; (* 6, 7, 9 and 12 will never show up, since they are suppressed *)
```

Versus:

```
david[x_] := 5; 6; 7; 9; 12; 17 (* 17 will **always** show up, since it is unsuppressed *)
```

What you have observed is one of the quirks of the Mathematica language.

Similar Questions

It's one of those days when I wonder: am I losing my mind? If I step through this simple javascript function, the execution skips from line 3 to line 7. function editStudy() { var studyindex = docume

Is there a Mathematica function that provides results equivalent to the unique() function in MATLAB? I realize I could use the Union[] function to obtain the unique elements of a list, but I would lik

Is there a way in Mathematica to check whether a plot is empty or not? By empty, I mean it is only showing the axes and not any data points. I have a function that, depending on its inputs, gives som

Please note that this page is only for a school project, its not meant to function as a payment page. My code executes on submit, but only gets as far as checking for the name, if there is a problem w

Q: Why does my count function only count as high as one when I have multiple integers? CODE: import random while True: value = 0 count = 0 right_counter = 0 value = int(input(Enter the amount of ques

PivotTables in Excel (or, cross tabulations) are quite useful. Has anyone already thought about how to implement a similar function in Mathematica?

Does anybody know if there is a built-in function in Mathematica for getting the lhs of downvalue rules (without any holding)? I know how to write the code to do it, but it seems basic enough for a bu

What am I doing wrong here? I have a piece of code that looks something like this: function getUserList(requestingUserId){ return customerRepo.getCustomersAllowedByUser(requestingUserId) .then(functio

When using constraints with simple equality in Mathematica 8, minimization doesn't work. E.g. FindMinimum[{x^2 + y^2, y == 1}, {x, y}] works ok in Mathematica 6, but gives errors in version 8. Can a

I installed the Windows Azure Storage Client for Windows Phone from Nuget Packages. I want list the name of containers. Why don't behave my st variable as a IEnumerable?

I just had a few questions on list and function operations. 1) If I have a function f[] and a list list, I want to apply f[] sequentially to every element of the list, much like Scan does, but rather

In Rust the main function is defined like this: fn main() { } This function does not allow for a return value though. Why would a language not allow for a return value and is there a way to return so

I am baffled at to why the Postgresql position function gives different results for what seems to be a straightforward test. Here is query #1: SELECT count(*) FROM dnasample D, ibg_studies ST, subject

One may set a Default value for the arguments of a function: Default[f] = 5; And then use: f[a_, b_.] := {a, b} f[1, 2] f[1] {1, 2} {1, 5} This creates the following Values: DefaultValues[f] DownV

Possible Duplicate: In jQuery, why does programmatically triggering ‘click()’ on a checkbox not immediately check it? Update: This only applies to jQuery 1.8 and below. This was fixed in jQuery 1.9.

Part of code in VHDL. Workspace ISE. My function does not return a value, and I do not understand why Note that appears to me in ISE is function 'con_integer14' does not always return a value. The F

This may be a stupid question, but I am unable to wrap my head around this. Consider the following piece of code: function throwError() { throw Error(can't touch this.); } var def = q.defer(); def.

I'm trying to plot the derivative of a mollifier function in Mathematica. It differentiates the function OK, and can plot the function using %, but I would like to be able to plot by assigning the der

In GHCi: (> means output) data Unit = Unit let x = Unit let y = () :p x > x = (_t1::Unit) :p y > y = () :i () > data () = () -- Defined in `GHC.Tuple' Why do Unit and () behave differentl

Find root of implicit function in Mathematica I have an implicit function, for example: f(x,y) = x^3 + x*y + y^2 - 36 I want to find the root, ie solutions to the equation f(x,y) = 0 Drawing the solut

I'm trying to fine tune some spacing on my page using margin and padding and they either won't work at all or they come out way more than expected. I have a simple page with a word wrapping unordere

Can someone who is familiar with mathematica tell me why my drawing wont generate? plot1 = ContourPlot3D[{x^2 + (y + 0.25)^2 + (z - 0.45)^2 = 0.25, x^2 + y^2 + (z + 0.5)^2 = 0.25, x^2 + (y + 0.5)^2 +

Why does the parentheses have to follow immediately after the new Function? The MSDN website was unclear regarding why this is an error. // Fails but only in IE6 var greetings = new SayHello; greeting

Does placing a SqlCommand.Connection in a using block close the connection in the same way as placing the SqlConnection in it's own using block? (Is #1 = #2) Example 1 using (var cmd = GetCommandWithC

I'm just getting started on Mathematica and trying to define a function for later use. The function is: test[x_]:=x^2 While I don't close Mathematica, I can use the function on my notebooks but when

For the following function KEYS = {} def get(kind): returns a new key of a particular kind global KEYS try: return KEYS[kind].pop(0) except (KeyError, IndexError): handmade_key = Key.from_path(kind,

I tested this code snippet but the first function is not executing while the second one does.Why is this? The same function works fine on hover event.. <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0

So I try simple sqlite3pp modified a bit code: #include <iostream> #include <sqlite3pp.h> using namespace std; int main(int argc, char* argv[]) { try { sqlite3pp::database db(test.db); {

I'm writing a simple Mathematica implementation of the black-scholes model and using Plot3D to plot the pricing surface. However, when I run this code, no plot is produced. My call and put functions t

I am trying to simplify some formulas like F[a,b,c]*F[a,c,b]+F[c,a,b] /. {a->1,b->2,c->3} where F[a,b,c] := LegendreP[a,x]+LegendreP[b,x]*LegendreP[c,x] And Mathematica can give a polynomi

I have the following code (i know how to do this working and in the right style, but cited it as an example only to ask a question and understand where is mistake): import MySQLdb import MySQLdb.curso

(Function('return this'))(); I observed this technique in instanbul for nodejs. When executed in a window it has a similar effect. It will also work regardless of where this is executed. Ie, inside o

I have some code written like so: class Invite(models.Model): STATE_UNKNOWN = 0 STATE_WILL_PLAY = 1 STATE_WONT_PLAY = 2 STATE_READY = 3 STATE_CHOICES = ((STATE_UNKNOWN, _(Unknown)), (STATE_WILL_PLAY

Why does the following function not end? (* funct1 is a different function that does end *) fun funct(a,b::bs)=let val c=a in funct1(c,a,b::bs); = ; = ; = ; = ; stdIn:15.54-17.2 Error: syntax error: d

if I do match (fun i -> i + 1) with (fun i -> i + 1) -> true;; It got rejected. Why OCaml does not allow function matching?

I have a function which I would like to maximize over an independent variable range, say a->b. How would I do this in Mathematica? The documentation does not provide an answer.

Does anyone know why there is no snwprintf function in the C standard library? I am aware of swprintf, but that doesn't have the same semantics of a true, wchar_t version of snprintf. As far as I can

I have searched the web, but I could not find the answer to my problem> Why does the C++ template code not compile? Once I remove the last line before the return statement, it compiles and runs as

I have the following function, it will always return True. Any ideas why and how to avoid it? Thanks folks. function validateStatuses(xyx){ var umm = ugh[xyx]; var selects = $('#cont_'+ugh.xyz+' .stat

My code var arr = ['a','b',1]; var results = arr.map(function(item){ if(typeof item ==='string'){return item;} }); This gives the following results [a,b,undefined] I don't want undefined in the

I've decided to update all my jquery to work with jquery 1.9.1 but I can find out why this script has stopped working. Works fine in all other jquery versions. // Typewriter function $.fn.Typewriter =

Why does this code give the error: RuntimeError: maximum recursion depth exceeded during compilation? print_test never calls itself, hence I would think it isn't a recursive function. def print_test()

The mathematica documentation on Evaluate at possible issues says: Evaluate works only on the first level, directly inside a held function Why does Mathematica have this limitation? So if I have an

Why does Format(1A,0.000000) return 0.041667?

Using Mathematica, I need to optimize a function that is defined in terms of BinCounts; the arguments that I want to maximize over define the bin cutpoints. I think the problem is that Mathematica exp

given this code: mql = window.matchMedia((max-width: 800px)); mql.addListener(mqlHandler); function mqlHandler(mql) { if(mql.matches) { alert('OK'); }; and this other code: if(Modernizr.mq((max-wi

I am trying to toggle some text, Q & A style with the question as a button that will display its answer when clicked. It functions fine when the CSS does not load the page with target element set

I am working with regexes in Access VBA (VBScript Regular Expressions 5.5) and there's some behaviuor I dont understand. Is this normal regex behaviour? Why? The input is some html ... id=devices_int

Why does passing passing an argument to an anonymous function effect the results? For instance, the below script shows a1 as a function(), and a2 as an array. var a1=(function(){return [1*2,2*2,3*2];}

This is the script that i tested when the page loads. window.onload = initAll; function initAll() { document.getElementById(pTag).innerHTML = Hello Java Script !; } The above script works fine ti