Sort an outline at every level: Difference between revisions

m
syntax highlighting fixup automation
(J draft)
m (syntax highlighting fixup automation)
Line 117:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">Sort_an_outline(data, reverse:=""){
;-----------------------
; get Delim, Error Check
Line 169:
result.=delim
return result
}</langsyntaxhighlight>
Examples: "Example of Data_2"<langsyntaxhighlight AutoHotkeylang="autohotkey">Data_2 =
(
zeta
Line 186:
MsgBox % Sort_an_outline(Data_2)
MsgBox % Sort_an_outline(Data_2, 1)
return</langsyntaxhighlight>
Output: tabulated for ease of reading, actual output is text only, Error check returns first line with inconsistent delimiter!<pre>
======================================================================================================
Line 225:
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 416:
fmt.Println("\nSecond unspecified outline, descending sort:")
sortedOutline(outline4, false)
}</langsyntaxhighlight>
 
{{out}}
Line 536:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">{-# LANGUAGE OverloadedStrings #-}
 
import Data.Tree (Tree(..), foldTree)
Line 692:
| x <- textLines
, s <- [T.takeWhile isSpace x]
, 0 /= T.length s ]</langsyntaxhighlight>
{{Out}}
<pre>Four-spaced (A -> Z):
Line 771:
 
=={{header|J}}==
Implementation:<langsyntaxhighlight Jlang="j">parse2=: {{
((=<./)y (1 i.~ -.@e.)S:0 m) m {{
({.y),<m parse2^:(*@#)}.y
Line 793:
sortout=: {{ if. L.y do. u~ ({."1 y),.u sortout each}."1 y else. u~y end. }}
 
unparse=: {{ ;<S:0 y }}</langsyntaxhighlight>
 
Task examples (task data defined below):<langsyntaxhighlight Jlang="j"> /:sortout&.parseout sample1
alpha
epsilon
Line 857:
gamma
delta
</syntaxhighlight>
</lang>
 
Data for task examples:
<langsyntaxhighlight Jlang="j">sample1=: {{)n
zeta
beta
Line 915:
iota
epsilon
}}</langsyntaxhighlight>
 
=={{header|Julia}}==
A <code>for</code> loop was used in the constructor, and recursive functions for sorting and printing.
<langsyntaxhighlight lang="julia">import Base.print
 
abstract type Entry end
Line 1,072:
println(y)
end
</langsyntaxhighlight>{{out}}
<pre>
Given the text:
Line 1,182:
There are several differences between the Julia original and our transcription. Most are due to the fact that Nim way to do some things is different of the Julia way to do it.
 
<langsyntaxhighlight Nimlang="nim">import algorithm, sequtils, strformat, strutils
 
type
Line 1,346:
epsilon""")
except ValueError:
echo getCurrentExceptionMsg()</langsyntaxhighlight>
 
{{out}}
Line 1,453:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Sort_an_outline_at_every_level
Line 1,538:
theta
iota
epsilon</langsyntaxhighlight>
{{out}}
<pre>
Line 1,636:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">javascript_semantics</span> <span style="color: #000080;font-style:italic;">-- (tab chars are browser kryptonite)</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">print_children</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">lines</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">children</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">indent</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">bRev</span><span style="color: #0000FF;">)</span>
Line 1,718:
<span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lines</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,783:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">'''Sort an outline at every level'''
 
 
Line 2,199:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>4-space indented (A -> Z):
Line 2,278:
* Routine(s) to output the data structure in the desire sort order.
 
<syntaxhighlight lang="raku" perl6line>my @tests = q:to/END/.split( /\n\n+/ )».trim;
zeta
beta
Line 2,383:
multi pretty-print (Str $struct, :$level = 0, :$ws = ' ', :$desc = False) {
say $ws x $level , $struct;
}</langsyntaxhighlight>
{{out}}
<pre>=======================================================
Line 2,497:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "/sort" for Sort
import "/fmt" for Fmt
 
Line 2,651:
 
System.print("\nSecond unspecified outline, descending sort:")
sortedOutline.call(outline4, false)</langsyntaxhighlight>
 
{{out}}
10,327

edits