Search Results
6/9/2025, 4:42:05 AM
>>105532697
Scheme is about composing with expressions and more specifically lambda expressions. You should not think with statements, like you would do with c++ or java, but with procedures. I would say that trying to take advantage of apply will make you closer to the lisp philosophy.
in c, you would check if a list/array is ascending ordered with a loop made of statements and operators, something like this
bool is_ascending (array a)
{
for (int i = 1; i < a.length(); ++i)
if (a[i] < a[i - 1])
return false;
return true;
}
in Scheme, < is a procedure, not an operator; it takes an arbitrary amount of arguments.
you can apply those arguments as a list with apply, so you would just do (apply < a)
apply is extremely powerful and makes you think differently than with c/java/...
Scheme is about composing with expressions and more specifically lambda expressions. You should not think with statements, like you would do with c++ or java, but with procedures. I would say that trying to take advantage of apply will make you closer to the lisp philosophy.
in c, you would check if a list/array is ascending ordered with a loop made of statements and operators, something like this
bool is_ascending (array a)
{
for (int i = 1; i < a.length(); ++i)
if (a[i] < a[i - 1])
return false;
return true;
}
in Scheme, < is a procedure, not an operator; it takes an arbitrary amount of arguments.
you can apply those arguments as a list with apply, so you would just do (apply < a)
apply is extremely powerful and makes you think differently than with c/java/...
Page 1