私はまだこのエイリアンの機能的パラダイムを学んでいます...
次のコードを Clojure で機能的に記述するにはどうすればよいでしょうか? この欠落部分は別の場所で定義されていると想定し、コメントで説明されているように動作します。ここでは、私がよく知っている Python を使用しています。
usernames = []
# just the usernames of all the connections I want to open.
cancelfunctions = {}
# this global contains anonymous functions to cancel connections, keyed by username
def cancelAll():
for cancel in cancelfunctions.values():
cancel()
def reopenAll():
cancelfunctions = {}
for name in usernames:
# should return a function to close the connection and put it in the dict.
cancelfunctions[name] = openConnection()
私が本当に知る必要があるのは、reopenAll 関数のように、コールバックの新しい dict を構築する方法だけですが、ここにさらにコンテキストを含めます。これは、ある種の機能パラダイムの残虐行為を犯している可能性があるためです。おそらくプログラム全体を修正したいと考えています。:)