Hi Ronaldo,
You wrote :
...
Second, functions may be much more complex than a simple
algebraicexpression as you suggest. Thanks to list comprehension and
conditionalexpressions, you can code iterations, recursions, tests
andpre-calculations inside a function. Here is a simple example that uses
yourformule_Bezier() function
...
// computes the list of Fibonacci numbers up to a limiting value greater
than 0
function Fibonacci(limit, _result) =
is_undef(_result)
? Fibonacci(limit,[0,1])
: let( n = len(_result) )
_result[n-1]+_result[n-2] > limit
? _result
: Fibonacci(limit, concat(_result, _result[n-1]+_result[n-2] ) );
Of course, I fully understand the method which I find too concentrated for
a good understanding of the code in cases of more elaborate writing than
the one you propose. From this point of view, the maintenance of such
functions is not very easy.
This writing is enabled thanks to the ternary operator "?" :
value = logical_expression_1 ? expression_2 : expression_3 ;
taken up in many languages in different forms which I personally don't like
very much and which I intentionally use infrequently. Moreover, this type
of writing is accepted by the C language in particular as shown by the
following code which uses the one you proposed to me in OpenSCAD :
//
---===========================#include
<string.h>#include <stdio.h>#include <stdlib.h>
//************************************************************
//** Fonction de concatenation pour simuler*
// la fonction* "concat"*
-
de la librairie d'OpenSCAD ;int joindre(int result, int val){
result[++result[0]] = val ; return(result)
;}//*****************************************************//
Illustration de l'équivalence d'écriture :int Fibonacci(int limit, int
result){ return (result[result[0]] + result[result[0]-1]) > limit
? result : Fibonacci( limit , joindre(
result , result[result[0]] +
result[result[0]-1] ) )
;}// Fonction d'appelvoid test_code(){ int result[1024] ; result[0] =
2 ; result[1] = 2 ; result[2] = 4 ; printf("\n\nSuite de Fibonacci départ
: %d,%d\n", result[1],result[2]) ; Fibonacci(200, result) ; for(int i=0;
i<result[0] ; i++)
-
{ printf( "result[0] = %3d result[%3d]= %5d\n"*
-
, result[0], i, result[i+1]*
-
) ;*
-
}*
-
return ;}*
[image: image.png]
-
//
---===========================*
As the C language is very typical, it took a bit to compose to program the
equivalent.
I will however point out that this type of ternary statment is very old
since this writing was very used in the language "Algol" (Algo 60), first
language that I had learned in the university at the beginning of the years
1960. I enclose an example below taken fron the programmer's guide that I
kept (statment 3 and othesr) :
[image: image.png]
This this type of programming was widely possible at the time and I didn't
quite agree with a lot of colleagues who found this instruction great.
regards,
Lou Papet
--
"Pourquoi faire simple quand on peut faire encore plus simple..." "Le plus
simple est de ne pas faire.....seulement si c'est possible !..."
Hi Ronaldo,
------------------------------------------------------------------------------------
You wrote :
*...*
*Second, functions may be much more complex than a simple
algebraicexpression as you suggest. Thanks to list comprehension and
conditionalexpressions, you can code iterations, recursions, tests
andpre-calculations inside a function. Here is a simple example that uses
yourformule_Bezier() function*
*...*
// computes the list of Fibonacci numbers up to a limiting value greater
than 0
function Fibonacci(limit, _result) =
is_undef(_result)
? Fibonacci(limit,[0,1])
: let( n = len(_result) )
_result[n-1]+_result[n-2] > limit
? _result
: Fibonacci(limit, concat(_result, _result[n-1]+_result[n-2] ) );
------------------------------------------------------------------------------------
Of course, I fully understand the method which I find too concentrated for
a good understanding of the code in cases of more elaborate writing than
the one you propose. From this point of view, the maintenance of such
functions is not very easy.
This writing is enabled thanks to the ternary operator "*?*" :
*value = logical_expression_1 ? expression_2 : expression_3 ;*
taken up in many languages in different forms which I personally don't like
very much and which I intentionally use infrequently. Moreover, this type
of writing is accepted by the C language in particular as shown by the
following code which uses the one you proposed to me in OpenSCAD :
*//============================================================#include
<string.h>#include <stdio.h>#include <stdlib.h>*
//************************************************************
*//*** Fonction de concatenation pour simuler*
*// la fonction** "concat"*
* de la librairie d'OpenSCAD ;int *joindre(int *result, int val){
result[++result[0]] = val ; return(result)
;}//************************************************************//***
Illustration de l'équivalence d'écriture :int *Fibonacci(int limit, int
*result){ return (result[result[0]] + result[result[0]-1]) > limit
? result : Fibonacci( limit , joindre(
result , result[result[0]] +
result[result[0]-1] ) )
;}//*** Fonction d'appelvoid test_code(){ int result[1024] ; result[0] =
2 ; result[1] = 2 ; result[2] = 4 ; printf("\n\nSuite de Fibonacci départ
: %d,%d\n", result[1],result[2]) ; Fibonacci(200, result) ; for(int i=0;
i<result[0] ; i++)*
* { printf( "result[0] = %3d result[%3d]= %5d\n"*
* , result[0], i, result[i+1]*
* ) ;*
* }*
* return ;}*
[image: image.png]
* //============================================================*
As the C language is very typical, it took a bit to compose to program the
equivalent.
I will however point out that this type of ternary statment is very old
since this writing was very used in the language "*Algol*" (Algo 60), first
language that I had learned in the university at the beginning of the years
1960. I enclose an example below taken fron the programmer's guide that I
kept (statment 3 and othesr) :
[image: image.png]
This this type of programming was widely possible at the time and I didn't
quite agree with a lot of colleagues who found this instruction great.
regards,
Lou Papet
--
*"Pourquoi faire simple quand on peut faire encore plus simple..." "Le plus
simple est de ne pas faire.....seulement si c'est possible !..."*