Longest common substring: Difference between revisions

add lambdatalk code
(added langur language example)
(add lambdatalk code)
Line 1,430:
</pre>
 
=={{header|Lambdatalk}}==
1) A pure lambdatalk version
<syntaxhighlight lang="scheme">
{def lcs
{def lcs.rec
{lambda {:a :b :w}
{if {or {< {W.length :a} 2} {< {W.length :b} 2} }
then {W.rest :w}
else {if {W.equal? {W.first :a} {W.first :b}}
then {lcs.rec {W.rest :a} {W.rest :b} :w{W.first :a}}
else {let { {:x {lcs.rec :a {W.rest :b} :w}}
{:y {lcs.rec {W.rest :a} :b :w}}
} {if {> {W.length :x} {W.length :y}}
then :x
else :y} }}}}}
{lambda {:a :b}
{lcs.rec :a# :b# #}}}
-> lcs
 
{lcs testing123testing thisisatest}
-> tsitest // 23000ms
</syntaxhighlight>
 
2) The pure lambdatalk version is very, very slow, 23000ms.
A much more easier and faster way is to build an interface with the javascript code entry, {{trans|Javascript}}, used as it is.
 
<syntaxhighlight lang="scheme">
{jslcs testing123testing thisisatest}
-> tsitest // 130ms
 
{script
// the lcs function code is in the javascript entry
 
LAMBDATALK.DICT["jslcs"] = function() {
var args = arguments[0].split(" ");
return lcs( args[0], args[1] )
};
}
</syntaxhighlight>
 
=={{header|langur}}==
99

edits