我正在尝试打印出我的二叉树,但Clojure让我很难正确打印出序列.
所以,我有一个节点列表,'(1 2 3)例如.
在每次迭代中,我想在每个元素之前和之后打印出具有多个空格的节点.
(defn spaces [n]
(apply str (repeat n " ")))
Run Code Online (Sandbox Code Playgroud)
太好了,这似乎有效.
所以,假设我有一个列表,nodes '(:a :b :c)我想在一行打印,如上所述,空格.
(println (map #(str (spaces before) % (spaces (dec before))) nodes))
Run Code Online (Sandbox Code Playgroud)
我有一个项目清单.使用地图我得到一个字符串对象列表.好的,所以我可以打印出来!
但这给了我这个:
(clojure.lang.LazySeq@d0b37c31 clojure.lang.LazySeq@105879a9 clojure.lang.LazySeq@8de18242)
Run Code Online (Sandbox Code Playgroud)
所以我用Google搜索了如何打印延迟序列,然后我开始使用print-str命令.根据文档,这打印到一个字符串,然后返回.
(println (print-str (map #(str (spaces before) % (spaces (dec before))) nodes)))
Run Code Online (Sandbox Code Playgroud)
但这给了我这个:
(clojure.lang.LazySeq@d0b37c31 clojure.lang.LazySeq@105879a9 clojure.lang.LazySeq@8de18242)
Run Code Online (Sandbox Code Playgroud)
没有变化..嗯.任何帮助是极大的赞赏.
我想尝试git在我的常规 Windows 提示符中使用,而不是在 Git Bash 中使用。仅仅是因为我可以使用 IntelliJ 提供的终端。我认为这是一个 1 分钟的修复,但我想不是。
当我尝试时,git pull origin <branch>我收到以下错误消息:
C:\Users\Username\Documents\Bitbucket\java-project>git pull
Could not create directory '/c/Username/.ssh'.
The authenticity of host 'bitbucket.org (131.103.20.167)' can't be established.
RSA key fingerprint is 12:8c:1b:f2:6d:14:6b:5c:3b:ec:aa:46:46:xy:7c:40.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/c/Username/.ssh/known_hosts).
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights …Run Code Online (Sandbox Code Playgroud) 我是Pharo的新手,我很难掌握一些概念,特别是subclassResponsibilty.
我有以下objecttree:
AbstractDictionary
--TreeBasedDictionary (not abstract)
--AbstractArrayDictionary
----SimpleDictionary (not abstract)
----FastDictionary (not abstract)
Run Code Online (Sandbox Code Playgroud)
所有3都实现了操作at:put:和at:(以及更多).我从今天类明白,我可以拉起来at:put:的AbstractDictionary具有以下实现:
at: thisKey put: thisValue
"insert new key / value pair"
^self
at: thisKey
put: thisValue
duplicate: [self error:'duplicate key']
Run Code Online (Sandbox Code Playgroud)
然后,我实现了一个梅托德at:put:duplicate:中TreeBasedDictionary and AbstractArrayDictionary(因为执行是后者的子类相同).然后,当我调用at:put:一个对象时,它不会在任何一个实例中找到它,TreeBasedDictionary , SimpleDictionary or FastDictionary 但是在查找树时它会在超类(AbstractDictionary)中找到这个方法.这将调用自我at:put:duplicate:.该方法由前面提到的3个类实现,然后指向进行初始调用的类的实例的self被发送到要执行的消息at:put:duplicate:.
现在,AbstractArrayDictionary,SimpleDictionary and FastDictionary所有人都有一个名为的方法size.继承树底部的两个类都实现了这个方法.AbstractArrayDictionary实现此方法如下
size
"dictionary size"
self subclassResponsibility
Run Code Online (Sandbox Code Playgroud)
假设我为我实现了这个方法TreeBasedDictionary,我想我应该在我的AbstractDictionary …
我有一个系统,我必须建模household,其中有一个TVSubscription.这可以是一个digital一个,或一个analog一个.
一user登录到SetTopBox.然后他就可以租了Movies.
所以目前的方案如下:
//Existing instantiated variables in scope
aMovie
aUser
aSetTopBox
//End
--> execute this command:
aUser rent: aVideo on: aSTB
Code:
User>>rent: aVideo on: aSTB
aVideo rentBy: self on: aSTB
Video>>rentBy: aUser on: aSTB
aUser rentActionMovie: self on: aSTB
User>> rentActionMovie: aMovie on: aSTB
aSTB rentActionMovie: aMovie by: self
STB>>rentActionMovie: aMovie by: aUser
(loggedInUser isNil)
ifTrue: [ loggedInUser := aUser.
--Do stuff to charge the …Run Code Online (Sandbox Code Playgroud) 我正在学习java,并且可以自己完成很多编码,没有任何问题。但我一直在书上读 - 在java中,对象通过调用其他对象的方法来相互交互?
我不确定我是否清楚地理解了这一点。例子就像,一个Robot具有moveForward()、等方法的类comeToBase()。increaseSpeed()现在如果有两个机器人对象,那么它们将如何相互作用以避免冲突?我很理解每个机器人对象都可以独立调用自己的方法并独立运行,但是对象之间的交互是如何发生的呢?有人可以根据上面的例子解释一下吗?
我必须使二叉树的实现实例化一个类型类:
class Set s where
add :: (Eq a) => a -> s a -> s a
remove :: (Eq a) => a -> s a -> s a
exists :: (Eq a) => a -> s a -> Bool
fold :: (a -> b -> b) -> s a -> b -> b
data BTree k v = Empty | Node k v (BTree k v) (BTree k v) deriving (Show)
Run Code Online (Sandbox Code Playgroud)
一切顺利,直到我必须为二叉树实现折叠.我遇到的问题是我真的不知道如何使用这样的签名保持我的函数的类型声明:(a -> b -> b).我实现了折叠,但我的匿名函数的函数签名有1个累加器和2个值:
foldBST …Run Code Online (Sandbox Code Playgroud) 我正在参加编译器课程,而且我正在重新编写介绍.它概述了编译器过程的工作原理.
不过我有点困惑.
在我的课程中,它指出:"此外,词法分析器通常会访问符号表以存储/获取有关某些源语言概念的信息".因此,这让我相信词法分析器实际上会构建一个符号表.我看到它的方式是他创建令牌并将最小值存储在一个表中并说明它是什么类型的符号.例如,像"x - > VARIABLE".
然后再次,当阅读谷歌点击时,我似乎只能找到关于解析器生成这个事实的模糊信息?但解析阶段是在词法分析阶段之后.所以我有点困惑.
符号表解析后的人口; 编译器构建 (解析器填充表的状态)
http://www.cs.dartmouth.edu/~mckeeman/cs48/mxcom/doc/Symbols.html 说"符号表是通过遍历语法树构建的." 语法树是由解析器生成的,对吧?(解析树).那么在解析器之前运行的词法分析器如何使用此符号表呢?
我理解词法分析器不能知道变量的范围以及符号tabe中包含的其他信息.因此我理解解析器会将此信息添加到表中.但是,词法分析器确实知道一个单词是变量,声明关键字等.因此它应该能够构建一个部分(?)符号表.也许它们可能是每个构建符号表的一部分?
我正在尝试使用C#,我构建了以下程序(见下文).
我明白动态和静态类型first是C.对于second动态类型也是C静态类型A.现在我想知道这可能会派上用场吗?
我也注意到(显然)视觉工作室不允许我打电话second.CallA().
现在请注意,当我在所有三种类型的静态类型上调用DoA()时,动态类型是C.在这种情况下,为什么不this指向那个班级呢?如果我在Java中记得正确(我可能会误会),那么self.methodA()就会开始从调用者实例查找inhertence树.因为它似乎不像这里.我可以创建这样的行为,还是这种语言的限制?
public class A
{
public void methodA()
{
Console.WriteLine("I am class A!");
}
public void DoA()
{
Console.Write("The type of this: " + this.GetType() + " - ");
this.methodA();
}
}
public class B : A
{
public void methodA()
{
Console.WriteLine("I am class B!");
}
}
public class C : B
{
public void methodA()
{
Console.WriteLine("I …Run Code Online (Sandbox Code Playgroud) 我正在使用Snap框架中的Haskell代码.一切正常但现在我需要清理一些代码.然而,经过几次尝试后,似乎我只有更多的代码.也许任何人都可以给我一些指示?
这是我的初始代码.问题是,我模式匹配一个Maybe对我来说非常错误的值.所以我想把它弄清楚.但是下一行会得到一个Maybe值,所以我不得不改变它..
handleNewUserPost :: Handler App (AuthManager App) ()
handleNewUserPost = do
Just username <- getPostParam "login"
exists <- usernameExists $ T.decodeUtf8 username
case exists of
True -> handleNewUserGet $ Just "Sorry, this username already exist."
False -> do
registerUser "login" "password"
redirect "/new_user"
Run Code Online (Sandbox Code Playgroud)
最终我来到这里:
handleNewUserPost :: Handler App (AuthManager App) ()
handleNewUserPost = do
username <- getPostParam "login" -- :t username = Maybe ByteString
validate username
where
validate Nothing = redirect "/new_user"
validate (Just username) …Run Code Online (Sandbox Code Playgroud) 我正在为Clojure中的程序编写基准.我有n线程同时访问缓存.每个线程都将访问缓存x时间.每个请求都应记录在文件中.
为此,我创建了一个代理,用于保存要写入的文件的路径.当我想写 send-off一个写入文件的函数并简单地返回路径.这样我的文件写入是无竞争条件的.
当我在没有代理的情况下执行我的代码时,它在几毫秒内完成.当我使用代理时,每次我的代码运行速度非常慢时,请求每个线程发送给代理.我在说几分钟.
(defn load-cache-only [usercount cache-size]
"Test requesting from the cache only."
; Create the file to write the benchmark results to.
(def sink "benchmarks/results/load-cache-only.txt")
(let [data-agent (agent sink)
; Data for our backing store generated at runtime.
store-data (into {} (map vector (map (comp keyword str)
(repeat "item")
(range 1 cache-size))
(range 1 cache-size)))
cache (create-full-cache cache-size store-data)]
(barrier/run-with-barrier (fn [] (load-cache-only-work cache store-data data-agent)) usercount)))
(defn load-cache-only-work [cache store-data data-agent]
"For …Run Code Online (Sandbox Code Playgroud) 我花了一些时间调试我的代码.
我发现的是相当奇怪的,我希望有人可以向我解释发生了什么.
首先,这给出了编译时错误:
double x = 5.0;
int y = x;
Run Code Online (Sandbox Code Playgroud)
是的,因为你必须明确地将它转换成双重使用(double).
我有一个带有以下构造函数的对象:
public class MovesValue {
private ArrayList<Integer> moves;
private Double value;
public MovesValue(Integer move, double value) {
this.moves = new ArrayList<Integer>();
moves.add(move);
this.value = value;
}
public MovesValue(ArrayList<Integer> moves, double value) {
this.moves = moves;
this.value = value;
}
public MovesValue() {
}
public MovesValue(double value) {
this.value = value;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我正在调用这样的构造函数:
int moveToMake = beginMoves;
MovesValue rv = new MovesValue(moveToMake);
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,Java调用了以double为参数的构造函数.
它不应该抱怨找不到合适的构造函数吗?
我已经创建了现在也使用Integer的构造函数.然而,令我惊讶的是,Java仍然会调用带有double的构造函数.它是否需要使用 …
我有一个页面显示(来自asp.net代码的html输出)房屋/属性.我构建了以下javascript,只需按一下按钮,就可以更改属性上的所有css类,这样html就不会改变,但是css类会改变,以获得2列视图.
这很好用.但后来我想,如果用户选择2列视图,并导航到下一页(它是一种分页列表),视图将重置回原始(开始1列).
所以我做了以下几点.如果用户单击按钮,并从1列视图转到2列视图,我将window.name中的值保存为1或2.
然后我在这里建立这个小脚本:
$(document).ready(setView());
function setView() {
if (window.name != null) {
if (window.name == 2) {
window.Show2Cols();
}
if (window.name == 1) {
window.Show1Col();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这有效.Show2Cols()方法如下所示:
function Show2Cols() {
alert("Show2Cols is executed");
var nodes = document.getElementById("panden").getElementsByTagName("div");
alert("Just got all nodes.");
for (i = 0; i < nodes.length; i++)
{....
Run Code Online (Sandbox Code Playgroud)
因此,当我更改页面时,它弹出"执行Show2Cols",但它并没有说"只是获得了所有节点".
因为这是我的第一个JS,它不会变得更复杂,我想问你们哪里存在问题?
我的猜测是on(document).ready()有效,但是.getElementById()方法还没有工作,因为页面上没有任何东西(直观地).
提前致谢.
clojure ×2
haskell ×2
java ×2
pharo ×2
smalltalk ×2
agents ×1
c# ×1
command-line ×1
fold ×1
git ×1
inheritance ×1
interaction ×1
javascript ×1
jquery ×1
methods ×1
monads ×1
object ×1
oop ×1
parsing ×1
windows ×1