Jump to content

Tokenize a string: Difference between revisions

Added two solutions for Bracmat
(Added two solutions for Bracmat)
Line 189:
PRINT</lang>
 
=={{header|Bracmat}}==
Solution that employs string pattern matching to spot the commas
<lang bracmat>( "Hello,How,Are,You,Today":?String
& :?ReverseList
& whl
' ( @(!String:?element "," ?String)
& !element !ReverseList:?ReverseList
)
& !String:?List
& whl
' ( !ReverseList:%?element ?ReverseList
& (!element.!List):?List
)
& out$!List
)
</lang>
Solution that starts by evaluating the input and employs the circumstance that the comma is a list constructing binary operator and that the string does not contain any other characters that are interpreted as operators on evaluation.
<lang bracmat>( get$("Hello,How,Are,You,Today",MEM):?CommaseparatedList
& :?ReverseList
& whl
' ( !CommaseparatedList:(?element,?CommaseparatedList)
& !element !ReverseList:?ReverseList
)
& !CommaseparatedList:?List
& whl
' ( !ReverseList:%?element ?ReverseList
& (!element.!List):?List
)
& out$!List
)
</lang>
=={{header|C}}==
{{works with|ANSI C}}
483

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.