Forwarded from .
Medium
為什麼 Telegram 不能搜尋中文訊息
深入解析 SQLite FTS
Forwarded from dnaugsuz
说句题外话,写 tailrec 替换 while 也是可以的
fun findFunction(name: String) {
var current: Scope; = this.scope
while (current != null) {
current[name]?.let { return it }
current = parent.scope
}
}
tailrec fun findFunction(name: String, scope: Scope) = scope[name] ?: findFunction(name, parent.scope)
fun findFunction(name: String) = sequence(this, Context::parent).map { it.scope[name] }.firstNotNull()
``Forwarded from dnaugsuz
或许 receiver 不能算参数,没法给优化 🤔
啊说起来我都不知道 tco 一般是怎么做静态分析的……菜
啊说起来我都不知道 tco 一般是怎么做静态分析的……菜
Forwarded from dnaugsuz
https://t.me/dsuse/11472
这个是 js 的动态尾递归优化(迫真)
这个是 js 的动态尾递归优化(迫真)
Telegram
duangsuse::Echo
推荐一个 tco 函数 #JavaScript #FP
function _argveq(xs, ys, rb_i) { var i = rb_i | Math.min(xs.length,ys.length);
if(xs.length !== ys.length) return false;
while (i!==0) { --i; if(xs[i] != ys[i]) return false; }
return true;
}
// op tailrec must rewrite its…
function _argveq(xs, ys, rb_i) { var i = rb_i | Math.min(xs.length,ys.length);
if(xs.length !== ys.length) return false;
while (i!==0) { --i; if(xs[i] != ys[i]) return false; }
return true;
}
// op tailrec must rewrite its…
Forwarded from dnaugsuz
的确不大好看(而且还加了个多余的参数改动检测)
大致就是返回一个闭包,第一次调用isActived=false,以后递归则直接返回,但把arguments写到闭包的cont_args变量里,让第一层的while循环再去 op.apply ,只保留一个cargs就做到了调用栈不使用。
等于一旦进行递归调用(函数已经在执行),直接改参数、跳转到原函数开头再执行一遍。
大致就是返回一个闭包,第一次调用isActived=false,以后递归则直接返回,但把arguments写到闭包的cont_args变量里,让第一层的while循环再去 op.apply ,只保留一个cargs就做到了调用栈不使用。
等于一旦进行递归调用(函数已经在执行),直接改参数、跳转到原函数开头再执行一遍。
Forwarded from dnaugsuz
哇,那个
不是异步所以能直接从标准库调用吗🤔,之前没有见过的新东西呢。 有 coroutine 能做到把执行状态放堆上 对递归算法应该会很有趣。
这个递归函数的状态就是 tree ,返回时结果 +1 ,如果在栈没满前把tree参数和求值状态存到堆上,算完末尾节点后再 resume 就可以避免栈溢出了,不知道 Scala 有没有。
generateSequence(Tree(null,null)) { left -> Tree(left,null) } 和 depth = DeepRecursiveFunction<Tree?,Int> { t,n -> maxOf(callRecursive(t.left), callRecursive(t.right))+1 } 真的好优雅,以至于命名长一点也无所谓…… 新的特性应该说是灵活应用吧。不是异步所以能直接从标准库调用吗🤔,之前没有见过的新东西呢。 有 coroutine 能做到把执行状态放堆上 对递归算法应该会很有趣。
这个递归函数的状态就是 tree ,返回时结果 +1 ,如果在栈没满前把tree参数和求值状态存到堆上,算完末尾节点后再 resume 就可以避免栈溢出了,不知道 Scala 有没有。
Forwarded from dnaugsuz
想起来之前我写过一个利用 sealed class 和 ADT Stack 改写递归程序的例子…… 很难看 https://github.com/duangsuse-valid-projects/three-kt-files/blob/41e8b20e64c810c252f34cce60b522967aeed154/src/commonMain/kotlin/Calc.kt#L103
如果实现动态把栈顶下n层给替换成1层 resume handler 也不容易啊, resumeCoroutineOrReturn 的参数都不知道给到哪,所以果然 callRecursive() 还是很对应的设计呢
如果实现动态把栈顶下n层给替换成1层 resume handler 也不容易啊, resumeCoroutineOrReturn 的参数都不知道给到哪,所以果然 callRecursive() 还是很对应的设计呢
GitHub
duangsuse-valid-projects/three-kt-files
2019/11/10: Three Kotlin files (RingBuffer, DiffAlgorithm, NumEqualize, etc.) - duangsuse-valid-projects/three-kt-files
duangsuse::Echo
#ce #Kotlin https://github.com/Mivik/kamet/ 的代码昨天下午重构了下,导览下大致结构: 依赖: com.bytedeco.llvm-platform, com.github.KiotLand:kiot-lexer Value, Type, TypeDescriptor, TypeCastManager, GenericValue, ValueRef, Attributes, Context, JITEngine, Parser, Lexer 辅助: exceptions…
嗯……我再想想 ParserKt 的 primitives
SDRies CDP PWOC SJITLL
Seq(tup,*es),Decide(*es),Repeat(fold,e)
item(x), elementIn(rng), satisfy(p)
Convert(p,equiv), Deferred(lazy_p), Piped(p,trans)
Pattern,PatternWrapper,OptionalPattern,ConstantPattern
SurroundBy(pair,e), JoinBy(join, e), InfixPattern(e), TriePattern/TrieBack/MapPattern/GreedyPattern, LayoutPattern(lay,e), LexicalScopedPattern(body)
Feed 现在除了 SourceLocated, FeedError 还要加一个 FeedControl { val isEnd; fun peekMany(n:Int):List } 了。
因为这样, PKT 才可以更好的兼容 /* 注释之类的而无需担心无法在 InfixPattern.read 之类的算法里很好的处理 skip 的问题 (一旦在'/'那consume了,就没法让 InfixPattern 再识别这个运算符了)
所以只需把 var lastItem 再加 val readBuffer ,在 peekMany 的时候加入、 consume 的时候先弹出 即可
SDRies CDP PWOC SJITLL
Seq(tup,*es),Decide(*es),Repeat(fold,e)
item(x), elementIn(rng), satisfy(p)
Convert(p,equiv), Deferred(lazy_p), Piped(p,trans)
Pattern,PatternWrapper,OptionalPattern,ConstantPattern
SurroundBy(pair,e), JoinBy(join, e), InfixPattern(e), TriePattern/TrieBack/MapPattern/GreedyPattern, LayoutPattern(lay,e), LexicalScopedPattern(body)
Feed 现在除了 SourceLocated, FeedError 还要加一个 FeedControl { val isEnd; fun peekMany(n:Int):List } 了。
因为这样, PKT 才可以更好的兼容 /* 注释之类的而无需担心无法在 InfixPattern.read 之类的算法里很好的处理 skip 的问题 (一旦在'/'那consume了,就没法让 InfixPattern 再识别这个运算符了)
所以只需把 var lastItem 再加 val readBuffer ,在 peekMany 的时候加入、 consume 的时候先弹出 即可
template typename<T>
T* maxIndexOf(T* src, size_t n) {
T* max; for (T* i=src[0]; i<n; i++) if (src[i] > *max) max = &i;
return max - src;
}
T* maxIndexOf(T* src, size_t n) {
T* max;
for (int i=0; i<n; i++) if (src[i] > *max) max = &src[i];
return max - src;
} 哇真棒果然默写下来了…… 虽然没意义GitHub
DimenX/intellic at master · Mivik/DimenX
A functional C++ headers collection. Contribute to Mivik/DimenX development by creating an account on GitHub.
Forwarded from Harry Chen
本周 Tunight:Object-oriented Programming in Scala
时间:5/30 19:00
主讲人:@Paul_Zhu
会议:651 8777 6664(Zoom) / 255 452 111(腾讯会议备用)
详情:https://tuna.moe/event/2020/scala-oop/
直播:https://live.bilibili.com/699121
时间:5/30 19:00
主讲人:@Paul_Zhu
会议:651 8777 6664(Zoom) / 255 452 111(腾讯会议备用)
详情:https://tuna.moe/event/2020/scala-oop/
直播:https://live.bilibili.com/699121
tuna.moe
金枪鱼之夜:Object-oriented Programming in Scala | 清华大学 TUNA 协会
清华大学 TUNA 协会原名清华大学学生网管会,注册名清华大学学生网络与开源软件协会,是由清华大学网络技术和开源软件爱好者、技术宅组成的团体。现阶段向校内外提供开源软件镜像等服务。
草, #Kotlin 这不就是传说中的 Pair<Int,String> 不 Either<Int,String> 不 (forall a. a) -> a 类型吗,草不是 Rank N type 啊
Forwarded from Raid via @eva_zh_subtitle_bot
换成 Interface?
fun test() {
login(object : Callable {
override fun <T> call(value: T): T {
return value
}
})
}
fun login(callable: Callable) {
callable.call("1")
callable.call(1)
}
interface Callable {
fun <T> call(value: T): T
}fun main() { WTF(1)/*.a*/ }
class WTF(n: Int) {
init { print(1) }
val a = "emm"
}Forwarded from Haruue | 春上ひつき
只有这种是不正确并且会丢数据的用法
val os = FileOutputStream(...)如果你用 java 的 try with resource 或者 kotlin 的 .use , 这个问题可能会没那么明显并且显得迷惑。
val bos = BufferedOutputStream(os)
bos.write(...)
os.close() // 应该要 bos.close();
Forwarded from Haruue | 春上ひつき
当然最好还是
val os = BufferedOutputStream(FileOutputStream(...)) 从根源解决这种问题, 并不是所有情况都能这样做(比如代码中需要使用到 fileOutputStream.getFD() )。