<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Why do these ways of referencing columns give different results? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Why-do-these-ways-of-referencing-columns-give-different-results/m-p/603248#M80644</link>
    <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;.&lt;BR /&gt;Thank you for this post - I will add it to my list of treasures :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;It gives some hint why &lt;FONT face="courier new,courier"&gt;Name Expr(As Column(colname))&lt;BR /&gt;&lt;/FONT&gt;[e.g. by&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;in&amp;nbsp;&lt;A href="https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/490220/highlight/true#M73282" target="_blank" rel="noopener"&gt;Re: Need help with expressions, column references, formulas and column renaming&lt;/A&gt;] is so useful!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I would have liked to say: I think I really understand now&amp;nbsp; - but some of the below results are still surprising to me.&lt;/P&gt;&lt;P&gt;I am still searching for a comprehensive documentation - e.g. how to find out&amp;nbsp;&lt;SPAN&gt;how&lt;STRONG&gt;&lt;EM&gt; a function handles its parameters.&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;When searching via &lt;FONT face="courier new,courier"&gt;contains&lt;/FONT&gt;, why does Jmp know that &lt;FONT face="courier new,courier"&gt;Column("abc") = :abc?&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "test", New Column( "abc" ), New Column( "def" ) );

collist = {:abc, :def, .}; // &amp;lt;&amp;lt;&amp;lt; added a missing value in position 3
row()=0; //to be sure that the row index is really 0 :)
colname = "abc";
col = As Name( colname); // abc
col2 = :name("abc"); // .
col3 = As Column(colname); // .
col4 = Name Expr(As Column(colname)); // :abc
col5 = Column(colname); // Column("abc")
col6 = Name Expr(Column(colname)); // Column( colname )

col;  // .
col2; // .
col3; // .
col4; // .
col5; // Column( "abc" )
col6; // Column( "abc" )

Show( Name Expr(  col ), Type(  col ), Contains( collist,  col ) ); // :abc, Number, 3
Show( Name Expr( col2 ), Type( col2 ), Contains( collist, col2 ) ); // . , Number, 3
Show( Name Expr( col3 ), Type( col3 ), Contains( collist, col3 ) ); // ., Number, 3
Show( Name Expr( col4 ), Type( col4 ), Contains( collist, col4 ) ); // :abc, Number, 3
Show( Name Expr( col5 ), Type( col5 ), Contains( collist, col5 ) ); // Column("abc"), Column, 1 (!)
Show( Name Expr( col6 ), Type( col6 ), Contains( collist, col6 ) ); // Column(colname), Column, 1 (!!)

Show( Contains( collist, Name Expr(col) ) ); //  1
Show( Contains( collist, Name Expr(col2) ) ); // 3
Show( Contains( collist, Name Expr(col3) ) ); // 3
Show( Contains( collist, Name Expr(col4) ) ); // 1
Show( Contains( collist, Name Expr(col5) ) ); // 1
Show( Contains( collist, Name Expr(col6) ) ); // 0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Nov 2023 21:25:49 GMT</pubDate>
    <dc:creator>hogi</dc:creator>
    <dc:date>2023-11-07T21:25:49Z</dc:date>
    <item>
      <title>Why do these ways of referencing columns give different results?</title>
      <link>https://community.jmp.com/t5/Discussions/Why-do-these-ways-of-referencing-columns-give-different-results/m-p/598421#M80219</link>
      <description>&lt;P&gt;I'm struggling to understand how JSL handles column references and keep running into bugs in my scripts for that reason.&lt;/P&gt;&lt;P&gt;Why are the following expressions giving different results?&lt;/P&gt;&lt;P&gt;What is the best way of dynamically passing column references to functions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table("test",
New Column("abc"),
New Column("def")
);

collist = {:abc, :def};

col = AsName("abc");
colname = "abc";

Show(Contains(collist, col));
Show(Contains(collist, AsName(colname)));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The output is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Contains(collist, col) = 0;
Contains(collist, As Name(colname)) = 1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:37:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Why-do-these-ways-of-referencing-columns-give-different-results/m-p/598421#M80219</guid>
      <dc:creator>MedianWalrus538</dc:creator>
      <dc:date>2023-06-08T16:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Why do these ways of referencing columns give different results?</title>
      <link>https://community.jmp.com/t5/Discussions/Why-do-these-ways-of-referencing-columns-give-different-results/m-p/598720#M80237</link>
      <description>&lt;P&gt;This expression does not store a column reference:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;col = AsName("abc");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the Contains() function returns 0 (false).&amp;nbsp; You should use the Column( "name" ) if you want to store a column reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 18:37:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Why-do-these-ways-of-referencing-columns-give-different-results/m-p/598720#M80237</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2023-02-08T18:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: Why do these ways of referencing columns give different results?</title>
      <link>https://community.jmp.com/t5/Discussions/Why-do-these-ways-of-referencing-columns-give-different-results/m-p/598874#M80245</link>
      <description>&lt;P&gt;Virtual rabbit hole ahead. Mark's answer may be all you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is a fascinating question. It sure looks like you should get the same answer, but...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unlike C and many other languages, the arguments to functions are not evaluated before the function is called. Instead the function determines how to handle its parameters. And, JSL has a variable type called expression, closely related to the value AsName returns. When you call a function with an expression argument, the function can choose what to do with the parameter. It might evaluate the expression; a+2 requires looking up the variable a and adding 2. Or it might manipulate the expression; head(a+2) returns &lt;EM&gt;add&lt;/EM&gt;. In your example, the expression is &lt;EM&gt;abc&lt;/EM&gt;, and looking it up means getting its value from a row in the data table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(This is hard, I spent an hour trying to make the comments correct and clear. I think they are correct.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "test", New Column( "abc" ), New Column( "def" ) );

collist = {:abc, :def, .}; // &amp;lt;&amp;lt;&amp;lt; added a missing value in position 3

col = As Name( "abc" );// the Right Hand Side evaluates to the expression abc, 
// and the expression is assigned to col. The 2nd argument to contains() is
// a name expression, and contains() evaluates that argument. It
// evaluates to missing because there is no subscript to pick a row.
Show( Name Expr( col ), Type( col ), Contains( collist, col ) ); // looks for a missing value
// Name Expr(col) = abc;
// Type(col) = "Number";
// Contains(collist, col) = 3;

colname = "abc";
// contains() evaluates the 2nd argument to a name, but does not
// do another evaluation of the name, so it locates the name
// in the list of names
Show( Type( As Name( colname ) ), Contains( collist, As Name( colname ) ) );
// Type(As Name(colname)) = "Name";
// Contains(collist, As Name(colname)) = 1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;finally,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Show( Name Expr( col ), Type( col ), Contains( collist, Name Expr(col) ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;does what you want; the 2nd argument to contains() has the nameexpr() wrapper that causes contains() to evaluate it to the name of the expression, &lt;EM&gt;abc&lt;/EM&gt;, not the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;edit: this is never easy! &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26800"&gt;@hogi&lt;/a&gt;&amp;nbsp; points out the head(a+2) example (above) is wrong in &lt;LI-MESSAGE title="Does Head evaluate its argument?" uid="729500" url="https://community.jmp.com/t5/Discussions/Does-Head-evaluate-its-argument/m-p/729500#U729500" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;; I think the answer is head() peeks at the argument to see if it is a variable holding an expression, and if not, evaluates it to see if it will produce an expression.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 16:09:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Why-do-these-ways-of-referencing-columns-give-different-results/m-p/598874#M80245</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2024-03-04T16:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why do these ways of referencing columns give different results?</title>
      <link>https://community.jmp.com/t5/Discussions/Why-do-these-ways-of-referencing-columns-give-different-results/m-p/603248#M80644</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;.&lt;BR /&gt;Thank you for this post - I will add it to my list of treasures :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;It gives some hint why &lt;FONT face="courier new,courier"&gt;Name Expr(As Column(colname))&lt;BR /&gt;&lt;/FONT&gt;[e.g. by&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;in&amp;nbsp;&lt;A href="https://community.jmp.com/t5/Discussions/Need-help-with-expressions-column-references-formulas-and-column/m-p/490220/highlight/true#M73282" target="_blank" rel="noopener"&gt;Re: Need help with expressions, column references, formulas and column renaming&lt;/A&gt;] is so useful!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I would have liked to say: I think I really understand now&amp;nbsp; - but some of the below results are still surprising to me.&lt;/P&gt;&lt;P&gt;I am still searching for a comprehensive documentation - e.g. how to find out&amp;nbsp;&lt;SPAN&gt;how&lt;STRONG&gt;&lt;EM&gt; a function handles its parameters.&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;When searching via &lt;FONT face="courier new,courier"&gt;contains&lt;/FONT&gt;, why does Jmp know that &lt;FONT face="courier new,courier"&gt;Column("abc") = :abc?&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "test", New Column( "abc" ), New Column( "def" ) );

collist = {:abc, :def, .}; // &amp;lt;&amp;lt;&amp;lt; added a missing value in position 3
row()=0; //to be sure that the row index is really 0 :)
colname = "abc";
col = As Name( colname); // abc
col2 = :name("abc"); // .
col3 = As Column(colname); // .
col4 = Name Expr(As Column(colname)); // :abc
col5 = Column(colname); // Column("abc")
col6 = Name Expr(Column(colname)); // Column( colname )

col;  // .
col2; // .
col3; // .
col4; // .
col5; // Column( "abc" )
col6; // Column( "abc" )

Show( Name Expr(  col ), Type(  col ), Contains( collist,  col ) ); // :abc, Number, 3
Show( Name Expr( col2 ), Type( col2 ), Contains( collist, col2 ) ); // . , Number, 3
Show( Name Expr( col3 ), Type( col3 ), Contains( collist, col3 ) ); // ., Number, 3
Show( Name Expr( col4 ), Type( col4 ), Contains( collist, col4 ) ); // :abc, Number, 3
Show( Name Expr( col5 ), Type( col5 ), Contains( collist, col5 ) ); // Column("abc"), Column, 1 (!)
Show( Name Expr( col6 ), Type( col6 ), Contains( collist, col6 ) ); // Column(colname), Column, 1 (!!)

Show( Contains( collist, Name Expr(col) ) ); //  1
Show( Contains( collist, Name Expr(col2) ) ); // 3
Show( Contains( collist, Name Expr(col3) ) ); // 3
Show( Contains( collist, Name Expr(col4) ) ); // 1
Show( Contains( collist, Name Expr(col5) ) ); // 1
Show( Contains( collist, Name Expr(col6) ) ); // 0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 21:25:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Why-do-these-ways-of-referencing-columns-give-different-results/m-p/603248#M80644</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-11-07T21:25:49Z</dc:date>
    </item>
  </channel>
</rss>

