similar to: return value of {....}

Displaying 20 results from an estimated 3000 matches similar to: "return value of {....}"

2023 Jan 09
3
return value of {....}
Dear Valentin, But why should {....} "return" a value? It could just as well evaluate all the expressions and store the resulting objects in whatever environment the interpreter chooses, and then it would be left to the user to manipulate any object he chooses. Don't you think returning the last, or any value, is redundant? We are living in the 21st century
2023 Jan 12
4
return value of {....}
Hello Akshay, R is quite inspired by LISP, where this is a common thing. It is not in fact that {...} returned something, rather any expression evalulates to some value, and for a compound statement that is the last evaluated expression. {...} might be seen as similar to LISPs (begin ...). Now this is a very different thing compared to {...} in something like C, even if it looks or behaves
2023 Jan 13
1
return value of {....}
R's { expr1; expr2; expr3} acts much like C's ( expr1, expr2, expr3) E.g., $ cat a.c #include <stdio.h> int main(int argc, char* argv[]) { double y = 10 ; double x = (printf("Starting... "), y = y + 100, y * 20); printf("Done: x=%g, y=%g\n", x, y); return 0; } $ gcc -Wall a.c $ ./a.out Starting... Done: x=2200, y=110 I don't like that
2023 Jan 09
1
return value of {....}
Returning the last value of { is the basis of functions not needing a return statement. Before R invokes a function (specifically a closure), it creates a new context. When R evaluates a call to return, it looks for a context to return from and finds the context of function, ending the context and the evaluation of the function body early. However, if you don't use return, R just returns the
2023 Jan 15
3
return value of {....}
I wonder if the real confusino is not R's scope rules? (begin .) is not Lisp, it's Scheme (a major Lisp dialect), and in Scheme, (begin (define x ...) (define y ...) ...) declares variables x and y that are local to the (begin ...) form, just like Algol 68. That's weirdness 1. Javascript had a similar weirdness, when the ECMAscript process eventually addressed. But the real
2023 Jan 09
2
return value of {....}
Unless you do something special within a function, only the value(s) returned are available to the caller. That is the essence of functional-type programming languages. You need to read up on (function) environments in R . You can search on this. ?function and its links also contain useful information, but it may too terse to be explicable to you. There are of course many available references on
2023 Jan 09
1
return value of {....}
Akshay, Your question seems a tad mysterious to me as you are complaining about NOTHING. R was designed to return single values. The last statement executed in a function body, for example, is the value returned even when not at the end. Scoping is another issue entirely. What is visible is another discussion. So, yes, if you can see ALL the variables, you might see the last one BUT there
2023 Jan 11
1
return value of {....}
I am more than a little puzzled by your question. In the construct {expr1; expr2; expr3} all of the expressions expr1, expr2, and expr3 are evaluated, in that order. That's what curly braces are FOR. When you want some expressions evaluated in a specific order, that's why and when you use curly braces. If that's not what you want, don't use them. Complaining about it is like
2023 Jan 10
1
return value of {....}
Dear Avi, Thanks for your reply...your exhortations are indeed justified...! But one caveat: I was not complaining about anything...just was curious of the rationale of a particular design....Thanks again... Thanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: R-help <r-help-bounces at r-project.org> on behalf of avi.e.gross at gmail.com
2023 Jan 10
1
return value of {....}
Fair enough, Akshay. Wondering why a design was chosen is reasonable. There are languages like python that allow unpacking multiple values and it is not uncommon to return multiple things from some constructs as in this: >>> a,b,c = { 4, 5, 6 } >>> a 4 >>> b 5 >>> c 6 But that is a bit of an illusion as the thing in curly braces is a very
2023 Jan 09
1
return value of {....}
?s 14:47 de 09/01/2023, akshay kulkarni escreveu: > Dear members, > I have the following code: > >> TB <- {x <- 3;y <- 5} >> TB > [1] 5 > > It is consistent with the documentation: For {, the result of the last expression evaluated. This has the visibility of the last evaluation. > > But both x AND y are created, but the
2023 Jan 16
1
return value of {....}
Richard, A slight addition to your code shows an important aspect of R, local vs. global variables: x <- 137 f <- function () { a <- x x <- 42 b <- x list(a=a, b=b) } f() print(x) ________________________________________ From: R-help <r-help-bounces at r-project.org> on behalf of Richard O'Keefe <raoknz at gmail.com> Sent: Sunday,
2023 Jan 09
1
return value of {....}
Perhaps the following may be of use to you. Consider: > f <- function(){ x <- 3; function(y) x+y} > x <- 5 ##What does this give? > f() ## Why? ## How about this? >f()(10) ## Why? ## If you remove "x <- 3" from the above, what will you get when you repeat the exercise? -- Bert On Mon, Jan 9, 2023 at 8:29 AM Bert Gunter <bgunter.4567 at gmail.com>
2023 Jan 16
2
return value of {....}
Richard, I sent my prior email too quickly: A slight addition to your code shows an important aspect of R, local vs. global variables: x <- 137 f <- function () { a <- x x <- 42 b <- x list(a=a, b=b) } f() print(x) When run the program produces the following: > x <- 137 > f <- function () { + a <- x + x <- 42 +
2023 Jan 09
1
return value of {....}
I suspect akshay is (or was? Not sure) unclear about what braces do. They are not closures... they create an expression that wraps multiple expressions into one expression... they are a little more like parentheses than closures. They are not intrinsically associated with creation of environments for holding variables. Functions are closures... they run in a call-specific environment that
2023 Jan 16
1
return value of {....}
Again, John, we are comparing different designs in languages that are often decades old and partially retrofitted selectively over the years. Is it poor form to use global variables? Many think so. Discussions have been had on how to use variables hidden in various ways that are not global, such as within a package. But note R still has global assignment operators like <<- and its partner
2001 May 30
2
environments
I would like to be able, inside a function, to create a new function, and use it as part of a formula as an argument to, say, gnls or nlme. for example: MyTop <- function(data=dta) { Cexp <- function(dose,A,B,m){...} Model <- as.formula(paste("y","~ Cexp(",paste(formals(Cexp),collapse =", "),")")) MyCall <-
2004 May 14
2
NLME model question
Dear R-helpers I have a problem related to the use of NLME I think is simply a matter of getting the nlme coding correct, but i cannot get my brain around it I am analysing some 24 growth curves of some cells , and i wanted to say that there are significant differences between the curves in two parameters that describe the pattern of growth. these parameters are from a logistic (r & k)
2023 Mar 19
1
lexical scoping for scripts......
Again, the answer is "interactivity does not matter". On March 19, 2023 12:54:28 PM PDT, akshay kulkarni <akshay_e4 at hotmail.com> wrote: >Dear Jeff, > I will not be running R command in the shell prompt. So there is no banner, no > prompt. Just running "myscript.R" from the shell prompt. or from crontab in Linux. I think you get the
2023 Mar 19
2
lexical scoping for scripts......
Dear Duncun, What if there is no interactive "session" running? I will be running my scripts automatically from crontab in Linux. THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: Duncan Murdoch <murdoch.duncan at gmail.com> Sent: Monday, March 20, 2023 12:20 AM To: akshay kulkarni <akshay_e4 at hotmail.com>; R