Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Expression vs. Functions

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Sep 20, 2018 3:34 AM
(3450 views)

I been struggling to understand the differences. It looks to me, at least on the surface that they accomplish the same thing but seeing how you get to choose there is a difference somewhere. If you fine folks wouldn't mind giving me the dumb downed explination with maye an example or two i would greatly appreciate it.

D

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

My take: Functions are for code that will be recurring. Expressions are for inserting code into other code.

Here's a simplified example:

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
onewayFunc = function({dt,Yaxis, Xaxis}, {Default Local},
plot = dt << Oneway(
Y( eval(Yaxis) ),
X( eval(Xaxis) )
);
return(plot);
);
Yaxis = expr({Column("height"), Column("weight")});
Xaxis = expr(Column("sex"));
onewayFunc(dt,Yaxis,Xaxis);
```

This code could be accomplished without expressions, but using it as an example. In general I would say always use functions, until you meet an edge case where an expression will get the job done.

Expressions also have several useful helper functions making them useful for arithmatic and alegebra:

```
Names Default To Here( 1 );
Simplify Expr( Expr( 2 * 3 * a + b * (a + 3 - c) - a * b ) );
//6 * a + 3 * b + -1 * b * c
```

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

My take: Functions are for code that will be recurring. Expressions are for inserting code into other code.

Here's a simplified example:

```
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
onewayFunc = function({dt,Yaxis, Xaxis}, {Default Local},
plot = dt << Oneway(
Y( eval(Yaxis) ),
X( eval(Xaxis) )
);
return(plot);
);
Yaxis = expr({Column("height"), Column("weight")});
Xaxis = expr(Column("sex"));
onewayFunc(dt,Yaxis,Xaxis);
```

This code could be accomplished without expressions, but using it as an example. In general I would say always use functions, until you meet an edge case where an expression will get the job done.

Expressions also have several useful helper functions making them useful for arithmatic and alegebra:

```
Names Default To Here( 1 );
Simplify Expr( Expr( 2 * 3 * a + b * (a + 3 - c) - a * b ) );
//6 * a + 3 * b + -1 * b * c
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Expression vs. Functions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Expression vs. Functions

In addition to using the dynamic nature of expressions, I see expressions as another way to make a subroutine. I could use a function or an expression as a subroutine. I prefer an expression when I want to delay evaluation, don't need parameters, and don't need a result returned. I prefer a user function when I need parameters or a return result.

Learn it once, use it forever!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Expression vs. Functions

Thank you Mark,

I started a new topic based on the information you were able to provide. Functions are definitely what i needed to understand as it significantly reduces the lines of code in my data pull script.

Here is the link https://community.jmp.com/t5/Discussions/How-to-loop-using-a-function/m-p/74841