Branching - deprecated?
8 posts
• Page 1 of 1
Branching - deprecated?
Has branching been removed in version 18?
Reports 'Here' is not defined.
Also noted that
being used to exit the function immediately, results in a syntax error.
- Code: Select all
test←{
⎕←1
→Here
⎕←2
Here:
⎕←3
}
Reports 'Here' is not defined.
Also noted that
- Code: Select all
→0
being used to exit the function immediately, results in a syntax error.
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
-
jmosk - Posts: 69
- Joined: Thu Jul 18, 2013 5:15 am
Re: Branching - deprecated?
Tradfns (traditional functions) support branching and labels today, just as in the before times, though discouraged by many or even shunned by some. Dfns have never supported them, using recursion (and guards) instead. See the Dyalog Programming Reference Guide (Ch. 2 Defined Functions & Operators, p. 116) for the restrictions, and elsewhere for the syntax of dfns/ops.
Cheers.
Cheers.
- petermsiegel
- Posts: 159
- Joined: Thu Nov 11, 2010 11:04 pm
Re: Branching - deprecated?
So if it is still supported, why does my example of →0 produce a SYNTAX error?
If I write a function where I wish to abort under some condition, it seems I can't use a →0 to exit.
So how do you perform this early exit without the →0.
How would you make a case statement where you wanted to jump to different labels based on the value?
If I write a function where I wish to abort under some condition, it seems I can't use a →0 to exit.
- Code: Select all
:If number > 100
⎕←'Too high, aborting'
→0
:endif
So how do you perform this early exit without the →0.
How would you make a case statement where you wanted to jump to different labels based on the value?
- Code: Select all
→(Case1, Case2, Case3, Case4)[i]
Case1: S1
→Next
Case2: S2
→Next
Case3: S3
→Next
Case4: S4
Next:
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
-
jmosk - Posts: 69
- Joined: Thu Jul 18, 2013 5:15 am
Re: Branching - deprecated?
Both of those examples work for me, I think there must be something else in your function causing a SYNTAX ERROR.
An alternative to your branch-based select statement would be:
An alternative to your branch-based select statement would be:
- Code: Select all
:Select i
:Case 1
S1
:Case 2
S2
:Else
⎕←'Bad i'
:EndSelect
-
Morten|Dyalog - Posts: 460
- Joined: Tue Sep 09, 2008 3:52 pm
Re: Branching - deprecated?
Morten reported the code worked for him. So I tried again.
Version: 18.0.38756.0 64 Unicode
Created: Jul 15 2020 at 19:56:53
Build ID: a3a21494
)ed test
VALUE ERROR: Undefined name: Here
test[2] →Here
∧ - is under the H in Here
)ed test
SYNTAX ERROR
test[2] →0
∧ is under the →
.
Version: 18.0.38756.0 64 Unicode
Created: Jul 15 2020 at 19:56:53
Build ID: a3a21494
)ed test
- Code: Select all
test←{
⎕←1
→Here
⎕←2
Here:
⎕←3
}
VALUE ERROR: Undefined name: Here
test[2] →Here
∧ - is under the H in Here
)ed test
- Code: Select all
test←{
⎕←1
→0
⎕←2
}
SYNTAX ERROR
test[2] →0
∧ is under the →
.
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
-
jmosk - Posts: 69
- Joined: Thu Jul 18, 2013 5:15 am
Re: Branching - deprecated?
OK, as Peter explained in one of the first posts in this thread: control structures and branching are only supported in TradFns. dfns are intended for making functional definitions using guards and recursion. No "moving parts".
-
Morten|Dyalog - Posts: 460
- Joined: Tue Sep 09, 2008 3:52 pm
Re: Branching - deprecated?
Ah - yes - this does in fact work while test←{ } does not allow →
test
1
3
- Code: Select all
r←test
⎕←1
→Here
⎕←2
Here:
⎕←3
test
1
3
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
-
jmosk - Posts: 69
- Joined: Thu Jul 18, 2013 5:15 am
Re: Branching - deprecated?
Please read the documentation on traditional functions and dfns. They are very different.
A couple of hints:
* dfns have lexical scope, tfns have not
* all variables in dfns are local by definition, in tfns they are global by default.
* dfns don't have control structures, tfns have
* tfns may have labels but dfns not
* tfns support jumping to labels/lines, dfns not
A couple of hints:
* dfns have lexical scope, tfns have not
* all variables in dfns are local by definition, in tfns they are global by default.
* dfns don't have control structures, tfns have
* tfns may have labels but dfns not
* tfns support jumping to labels/lines, dfns not
-
kai - Posts: 139
- Joined: Thu Jun 18, 2009 5:10 pm
- Location: Hillesheim / Germany
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group