首页 \ 问答 \ java.lang.ClassCastException:java.lang.Long无法强制转换为clojure.lang.IFn [复制](java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn [duplicate])

java.lang.ClassCastException:java.lang.Long无法强制转换为clojure.lang.IFn [复制](java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn [duplicate])

这个问题在这里已有答案:

这是我的第一个问题,希望你能帮助我。 我正在编写clojure中的合并函数。 我在tryclojure上测试我的代码,并在标题中得到错误。

这是我的代码

(def merge
(fn [lon1 lon2]
{:pre[(every? number? lon1)(every? number? lon2)]
:post[(every? number? %)]}
(cond
(empty? lon1) lon2
(empty? lon2)lon1
:else
(cons (min (first lon1) (first lon2))
(merge (rest lon1) (rest lon2))))))
#'sandbox7750/merge
> (merge (1,2,5) (3,4))
java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn

那么,这里的问题是什么? 期待答案:)

问候


This question already has an answer here:

this is my first question here and i hope you can help me. I am programming a merge function in clojure. I test my code on tryclojure and got the error in the title.

Here is my Code

(def merge
(fn [lon1 lon2]
{:pre[(every? number? lon1)(every? number? lon2)]
:post[(every? number? %)]}
(cond
(empty? lon1) lon2
(empty? lon2)lon1
:else
(cons (min (first lon1) (first lon2))
(merge (rest lon1) (rest lon2))))))
#'sandbox7750/merge
> (merge (1,2,5) (3,4))
java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn

So, whats the Problem here? Looking forwards to an answer :)

greetings


原文:https://stackoverflow.com/questions/37654062
更新时间:2022-07-10 18:07

最满意答案

这是从我在博客上发表的一篇文章,回答几乎完全相同的问题 。 它包含了许多已经在这里给出的答案,以及一些额外的建议,其中一些是我的个人意见,其他可能与我不同。 希望有人觉得有用:

建立东西

我可以提供的最好的建议是开始建立一些东西。 Django的一个典型的“Hello world”是一个博客网站,我也建议从此开始。 Django框架尝试使常见任务变得非常简单和简单,而具有简单博客功能的网站就是一个典型的例子。 流畅的Djangonaut可以通过使用所有可用的图书馆在不到一个小时的时间内编写一个简单的博客网站,因此它是开始Django做事情的好地方。

Django书

当然,在您可以跳入并开始编码之前,您需要使用Django让系统启动并运行,并学习基础知识。 一个伟大的资源是Django Book 。 作者在一段时间内还没有完成任务,或者保持原状(由于年轻的性质,Django的变化非常的频繁),但是它是免费的在网上提供,强烈推荐。 阅读关于如何设置系统的前几章,Django的所有部分如何融合到MVC模型中,并感到惊讶的是Django如何做到这一点,使得其他框架变得非常复杂。

Django教程和文档

Django网站上有很多很棒的教程,一旦你拥有Django的基础知识,几乎不需要任何其他的教程。 文件也很棒,去看看你自己。

选择Django版本

对于初学者来说,选择Django版本是一个好主意,并坚持下去。 在撰写本文时,大多数Django 1.2和Django 1.3都使用了两个主要版本,以及开发版本(Django开发人员的版本以及在作为主要版本发布之前测试更改的版本) )。 开始时不要使用开发版本 - 你一定会遇到麻烦。

最重要的是,Django现在已经存在了大约四五年了,你将会发现大部分分布在Google上的教程将针对Django 1.0和1.1。 没关系,大多没有问题,但Django自那以来添加了很多功能,这些教程和代码片段大部分已经过时了。 尽可能坚持使用针对您的版本的教程。

选择版本后,请确保始终阅读正确版本的Django文档 。 您将在右侧侧栏和您所在页面的网址中看到,您可以更改您正在查看的版本。 Django的文档是真正优秀的,远远超过了其他任何东西,作者非常小心,具体说明哪个功能是新版本的功能,哪些功能在以后的版本中被弃用。 只要确保你知道这一点,这样你不会浪费无数小时,试图让你的版本中不可用的工作。

知道DRY是什么意思,并练习它

DRY:“不要重复自己”是Django背后的核心原则之一。 如果您发现自己在Django中复制任何东西,几乎肯定会有更好的方法。 大多数程序员会从经验中知道为什么这样的复制是坏的,但总之,如果您的代码中的某些内容需要稍后更改,或者如果您在某处发生错误,则只需要在一个地方更改。 这很有用,因为如果有多个地方需要改变,而且你忘记了这个实例,那么你会在你的代码中引入错误和错误。

远离课堂观点

Django 1.3的一个新增功能是基于类的通用视图的整个数组。 如果你不知道这是什么意思,别担心。 绝大多数关于Django的教程和书籍都不会提及,主要是因为它是如此新鲜。 这是一个功能,旨在减少创建视图的复制,从而遵循DRY原则。 虽然它在某种程度上做到了这一点,但它也引入了很多黑魔法,并且需要经常在Django源代码中去查看发生了什么。 对于初学者来说,这不太理想。 此外,现在为基于类的视图提供的错误消息通常会指向完全错误的方向。 远离他们,而是开始使用功能视图,因为大多数教程将告诉你。 当您对Django有更多的用处时,您会发现功能视图的复制令人沮丧,请查看基于类的通用视图。

不要开始在Google App Engine上托管

虽然GAE对于可伸缩的Django应用程序来说是免费的,但它也为您的登录过程引入了很多限制,其中的文档极其稀缺。 作为一个初学者,不要以这种方式开始,因为许多正常的Django文档将突然不适用,你不会知道该怎么做。 相反,从一个像epio , gondor.io或许多其他服务开始。 Epio仍处于测试阶段,但也有一个免费的托管选项(达到一定的月度使用量)。 由两个Django核心开发人员开发,我强烈建议使用它们,它与Ruby on Rails的Heroku相当。 Ep.io正在关闭,但Heroku最近还添加了一个Python托管选项 。

使用StackOverflow,提出问题

我最后的建议是在任何时候卡住的时候使用StackOverflow。 首先,他们已经有了你可以想到的任何问题的答案。 如果您在网站上找不到,找到问题答案的好方法是将“stackoverflow”作为您的google搜索条件的一部分。 否则,发布一个问题,让Django社区帮助你。 除了身体阅读Django代码(您还应该做的)之外,在过去几年里,我已经被证明是我学习Django黑暗层面的最好的资源。 祝你好运,享受!


This is from a post I made on my blog, answering almost exactly same question. It contains many of the answers already given here, as well as some extra advice, and some of it is my personal opinion, and others may differ from me. Hopefully someone finds it useful:

Build Something

The best advice I can give is to start by building something. A typical "Hello world" for Django is a blog website, and I would also recommend starting with that. The Django framework tries to make common tasks extremely easy and simple, and a website with simple blogging functionality is a typical example. A fluent Djangonaut can code up a simple blog website in less than an hour by using all the libraries available, and therefore it's a good place to start and get a feel for how Django does things.

The Django Book

Of course, before you can just jump in and start coding, you need to get your system up and running with Django, and learn the basics. A great resource for that is the Django Book. The authors haven't worked on it in a while or kept it quite up to date (due to its young nature, Django changes quite frequently), but It's freely available online and highly recommended. Read the first few chapters on how to set up your system, how all the parts of Django fit together into the MVC model, and be amazed by how Django does things so simply that other frameworks made unnecisarily tiresome.

The Django Tutorials and Documentation

There are so many great tutorials on the Django website, that you'll almost need nothing else once you have the basics of Django down. The documentation is also fantastic, go take a look for yourself.

Pick a Django Version

For a beginner, it will be a good idea to pick a Django version, and stick with it. At the time of this writing, there are two main versions being used by most, Django 1.2 and Django 1.3, as well as the development version (the version that the Django developers work on and test changes in before it gets released as a major version). Don't use the development version when you're starting out - you're bound to run into trouble.

The big thing is that Django has existed for around four or five years now, and much of the tutorials you'll find scattered over Google will be aimed at Django 1.0 and 1.1. That's fine, and mostly not a problem, but Django's added quite a lot of functionality since then that makes most of those tutorials and code snippets obsolete. Try to stick to tutorials that are aimed at your version, where possible.

Once you've picked a version, make sure you always read the correct version of the Django documentation. You'll see on the right-hand side sidebar and in the url of the page you are on that you can change the version you're looking at. Django's documentaion is truly excellent and far beyond anything else out there, and the authors take great care to specifically state which functions are new to that version, and which are deprecated in later versions. Just make sure you're aware of that, so that you don't waste countless hours trying to make something work that's not available in your version.

Know what DRY means, and practice it

DRY: "Don't Repeat Yourself" is one of the core principles behind Django. If you find yourself copy-pasting anything in Django, there's almost certainly a better way to do it. Most programmers will know from experience why repitition like that is bad, but in short, if something in your code needs to change later on or if you made a mistake somewhere, you only need to change it in one place. That's useful, because if there is more than one place needing change, and you forget about that instance, you'll be introducing errors and bugs into your code.

Stay away from Class-based views

A new addition to Django 1.3 is a whole array of Class-based Generic Views. If you don't know what that means, don't worry. The vast majority of tutorials and books about Django won't make any mention of it, mainly because it is so new. It's a feature that is meant to lessen the repitition in creating views, thereby following the DRY principle. While it does do that to some extent, it also introduces a lot of black magic and the need to frequently go scratch around in the Django source code to see what's going on. For the beginner, that is less than ideal. In addition, the error messages as they are now provided for Class-based views often point you in the completely wrong direction. Stay away from them, and rather use functional views in the beginning, as most tutorials will tell you to. When you're a bit more used to Django and you find the repitition of functional views frustrating, look into Class-based Generic Views.

Don't start out hosting on Google App Engine

While GAE is free and great for scalable Django apps, it also introduces a lot of restrictions on your login process, and the documentation on that is extremely scarce. As a beginner, don't start out with that route, since lots of the normal Django documentation will suddenly not apply, and you won't know what to do. Rather, start with a service like epio, gondor.io, or many others . Epio's still in beta, but have a free hosting option as well (up to a certain amount of monthly usage). Developed by two of the Django core developers, I strongly recommend using them - it's comparable to Heroku for Ruby on Rails. Ep.io is closing down, but Heroku also recently added a Python hosting option.

Use StackOverflow, Ask questions

My final piece of advice is to make use of StackOverflow any time you get stuck. First off, they already have the answer to just about any question you can dream of. If you can't find it on the site, a good way to find the answer to your question is to append "stackoverflow" as part of your google search terms. Otherwise, post a question and let the Django community help you out. It's proven to be my greatest resource in learning the darker sides of Django over the last few years, apart from physically reading the Django code (which you should also do!). Good luck, and enjoy!

相关问答

更多
  • 这是一个很棒的项目清单。 如果您向下滚动,您将看到很多开源项目。 您可以下载它们并查看模型/视图等: http : //code.djangoproject.com/wiki/DjangoResources 其中很多都是托管在Google代码上。 只需点击Google代码中的“源”链接标签,然后将SVN Trunk网址复制到浏览器中即可在线查看代码。 更新:另一个伟大的资源是www.djangopackages.com ,其中列出了大部分着名的Django应用程序,其中包括各自代码库(GitHub等)的链接 ...
  • Ruby on Rails: 容易学习? - 是 - 参考guide.rubyonrails.org的优秀文档和railstutorial.org上的一个很棒的教程。 易于构建和迭代? - 确实,轨道很好地适应了敏捷和迭代的发展。 易于部署? - 部署(至少对于小型应用程序和学习),你不能比使用heroku.com - git的推送更容易,它是免费的。 人气 - 非常受欢迎! Django的 容易学习? - 像Rails,Django在docs.djangoproject.com/en/1.3/中有出色的文 ...
  • 一些介绍您在Rational Unified Process最佳实践中找到的词语 IBM Rational是一个很好的起点 A few introducing words you find in Rational Unified Process Best Practices A good starting point is IBM Rational
  • 这是从我在博客上发表的一篇文章,回答几乎完全相同的问题 。 它包含了许多已经在这里给出的答案,以及一些额外的建议,其中一些是我的个人意见,其他可能与我不同。 希望有人觉得有用: 建立东西 我可以提供的最好的建议是开始建立一些东西。 Django的一个典型的“Hello world”是一个博客网站,我也建议从此开始。 Django框架尝试使常见任务变得非常简单和简单,而具有简单博客功能的网站就是一个典型的例子。 流畅的Djangonaut可以通过使用所有可用的图书馆在不到一个小时的时间内编写一个简单的博客网站 ...
  • 如果你喜欢Ruby,你可能会喜欢Smalltalk。 IIRC海滨已被移植到宝石VM,它是宝石/ S OODBMS的一部分。 这比Ruby有更好的线程支持,因此它是高容量系统的更好的后端。 这可能是一个很好的理由仔细看看它。 学习Smalltalk的原因: 这是一个非常好的编程环境。 一旦你有头脑(对于习惯于C ++或Java的人来说,它往往是一种文化冲击),你会发现它是一个非常好的环境,即使是一个非常糟糕的smalltalk像我使用的老Digitalk是一个非常愉快的系统使用。 许多古老的XP和OO大师类 ...
  • ajax的基础是对象XMLHTTPRequest。 因此,您可以在这里学习W3C规范,并在w3schools学习教程。 编辑 可能你使用的是框架,所以要了解jQuery ajax 。 The base of ajax is the object XMLHTTPRequest. So, you could learn the W3C specification here and a tutorial at w3schools. EDIT Probably you use a framework, so lea ...
  • Python和Django的官方教程都很好。 有很多免费的Python书籍。 如果你对教程不满意, Django Book (免费)由它的创建者完成是非常棒的。 The official tutorials for Python and Django are both good. There are so many freely available books on Python. Django Book (free) by it's creators is great if you are not sat ...
  • 有关jQuery的介绍,你无法击败jqFundamentals 。 它对jQuery进行了很好的介绍,但只有在它涵盖了所有Javascript基础知识之后。 我不能高度推荐它! For an introduction to jQuery, you can't beat jqFundamentals. It gives a great introduction to jQuery, but only after it covers all the Javascript basics as well. I ca ...
  • 这将是一个开始jQuery教程的好地方。 在这方面,John Resig 介绍了jQuery的工作原理。 This would be a good place to start for jQuery tutorials. In that, John Resig has a basic intro on how jQuery works.
  • 我们认为Google Cloud Dataflow是开始使用大数据分析的绝佳场所。 我们从头开始构建它,简单易用。 有关其他数据处理技术的知识,例如MapReduce或Hadoop,可以帮助您入门,但它们在学习或使用Cloud Dataflow方面不会有太大的帮助。 但是,有了这样的背景,Cloud Dataflow提供的完全托管服务的好处将更加明显。 一个好的起点是我们的主页 。 你会在那里找到所有相关信息。 如果出现任何问题,请随意使用google-cloud-dataflow标记StackOverfl ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)