How to resolve the algorithm Optional parameters step by step in the Ursala programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Optional parameters step by step in the Ursala programming language

Table of Contents

Problem Statement

Define a function/method/subroutine which sorts a sequence ("table") of sequences ("rows") of strings ("cells"), by one of the strings. Besides the input to be sorted, it shall have the following optional parameters: This task should be considered to include both positional and named optional parameters, as well as overloading on argument count as in Java or selector name as in Smalltalk, or, in the extreme, using different function names. Provide these variations of sorting in whatever way is most natural to your language. If the language supports both methods naturally, you are encouraged to describe both. Do not implement a sorting algorithm; this task is about the interface. If you can't use a built-in sort routine, just omit the implementation (with a comment). See also:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Optional parameters step by step in the Ursala programming language

Source code in the ursala programming language

#import std
#import nat

ss ::

ordering   %fZ ~ordering||lleq!
column     %n  ~column||1!
reversed   %b

sorter = +^(~reversed?/~&x! ~&!,-<+ +^/~ordering ~~+ ~&h++ //skip+ predecessor+ ~column)

example_table = 

<
   <'foo','b  '>,
   <'barr','a '>,
   <'bazzz','c'>>

#cast %sLLL

examples =

<
   (sorter ss&) example_table,                      # default sorting algorithm
   (sorter ss[ordering: leql]) example_table,       # sort by field lengths but otherwise default
   (sorter ss[column: 2]) example_table,            # etc.
   (sorter ss[reversed: true]) example_table,
   (sorter ss[reversed: true,column: 2]) example_table>

  

You may also check:How to resolve the algorithm Hailstone sequence step by step in the CLU programming language
You may also check:How to resolve the algorithm Pragmatic directives step by step in the Tcl programming language
You may also check:How to resolve the algorithm Cartesian product of two or more lists step by step in the C# programming language
You may also check:How to resolve the algorithm LU decomposition step by step in the jq programming language
You may also check:How to resolve the algorithm Flow-control structures step by step in the Wren programming language