当前位置: 首页 > news >正文

网站运营内容seo优化怎么做

网站运营内容,seo优化怎么做,用thinkcmf做的网站,网站文章收录查询如何正确地写出Scala的第一个程序,并且利用Scala3的简洁特性? 在解释器中直接输出Hello world非常简单,只需要直接执行即可: scala> println("Hello World") Hello World 但如果我们希望编写一个脚本文件&#xf…

如何正确地写出Scala的第一个程序,并且利用Scala3的简洁特性?

在解释器中直接输出Hello world非常简单,只需要直接执行即可:

scala> println("Hello World")
Hello World

但如果我们希望编写一个脚本文件,编译后执行再输出Hello World,却会踩到很多的坑。

错误的尝试1

方案来源:书籍:敏捷硬件开发语言Chisel与数字系统设计

博客:如何运行scala脚本 | 我的站点

首先创建一个.scala文件

vim hello.scala

在这个文件中编写如下代码:

println("Hello World!")

然后执行编译指令

scala hello.scala

之后,他们说这样就可以成功输出Hello world。然而,除了报错你什么都得不到:

jia@J-MateBookEGo:~/scala_test$ scalac hello.scala
-- [E103] Syntax Error: hello.scala:1:0 ----------------------------------------
1 |println("Hello, World!")|^^^^^^^|Illegal start of toplevel definition|| longer explanation available when compiling with `-explain`
1 error found

并不错误,但不太好的尝试2 

经过查找资料,我找到了CSDN的一篇博客,里面记录了Scala的第一个程序,包括网上的课程也是这样讲的:(地址:第一个Scala程序——Hello World!_scala hello world-CSDN博客)

注意,他这里没有写等号,实际上没有写等号也会报错,等号必须写,另外这里必须是object,不可以是class,原因和Scala使用了JVM有关,这里不多赘述

object HelloWorld {def main(args: Array[String]) = {println("Hello, world!")}
}

之后进行编译:

jia@J-MateBookEGo:~/scala_test$ scala hello.scala
Compiling project (Scala 3.6.2, JVM (21))
Compiled project (Scala 3.6.2, JVM (21))
Hello, world!

这里使用scala或者scalac都可以编译成功,只不过使用scala会自动执行。

成功的步骤

这样我们能够成功输出Hello world,但书中和博客应该并非空穴来风,直接编写简洁的函数能否实现功能,答案是可以。我们查询官网:Hello, World! | Scala 3 — Book | Scala Documentation

官网说明,Scala2的第一个程序应该这样写:

object hello {def main(args: Array[String]) = {println("Hello, World!")}
}

官网的解释:代码中,在名为 hello 的 Scala object 中,我们定义了一个名称为 main 的方法。 在 Scala 中 object 类似 class,但定义了一个可以传递的单例实例。 main 用名为 args 的输入参数,该参数必须是 Array[String] 类型(暂时忽略 args)。

这和我们上面写的是一致的,但对于Scala3有着更简明的写法:

@main def hello() = println("Hello, World!")

这个@main写不写都可以,并不影响,但必须用def定义。官网解释如下:代码中, hello 是方法。 它使用 def 定义,并用 @main 注释的手段把它声明为“main”方法。 使用 println 方法,它在标准输出 (STDOUT)中打印了 "Hello, world!" 字符串。

这里直接使用scala编译并运行:

jia@J-MateBookEGo:~/scala_test$ scala hello.scala
Compiling project (Scala 3.6.2, JVM (21))
Compiled project (Scala 3.6.2, JVM (21))
Hello, World!

没问题,成功运行了。但官网使用的是scalac,他要求我们使用以下两条指令编译并运行:

scalac Hello.scala
scala hello

事实上,它又报错了:

jia@J-MateBookEGo:~/scala_test$ scalac hello.scala
jia@J-MateBookEGo:~/scala_test$ scala hello
[error]  hello is not a scala sub-command and it is not a valid path to an input file or directory.
Try viewing the relevant help to see the list of available sub-commands and options.scala --help

不是哥们,你官网写的文档也是错的是什么意思,没办法我们只能继续搜索这个报错,在github上找到了解答:Document starting programs compiled by scalac in the current working directory · Issue #3132 · VirtusLab/scala-cli · GitHub

其中的意思大概翻译一些就是:这种写法已经不被支持了,我们早就已经讨论在新的标准中不支持它。

不支持可以啊,那你官网怎么还放着以前的版本,这也太草率了吧,只能说默认学这门语言的不是小白吧。。。。。。

解决方案就是,不能直接使用scala hello执行这个脚本,而需要使用这两条指令中的任意一条:

scala run -cp .
scala run -cp . -M hello

第一条指令运行失败,第二条运行成功。

jia@J-MateBookEGo:~/scala_test$ scala run -cp .
[error]  Found several main classes: hello, hello, hello
You can run one of them by passing it with the --main-class option, e.g.scala run -cp . --main-class helloYou can pick the main class interactively by passing the --interactive option.scala run -cp . --interactive
jia@J-MateBookEGo:~/scala_test$ scala run -cp . -M hello
Hello, World!

总结

成功的运行方式如下:

脚本代码:

@main def hello() = println("Hello, World!")

编译指令:

scala hello.scala

或者:

scalac hello.scala
scala run -cp . -M hello

文章转载自:
http://pyelogram.Lgnz.cn
http://elucubrate.Lgnz.cn
http://pluto.Lgnz.cn
http://pelisse.Lgnz.cn
http://prevue.Lgnz.cn
http://sherut.Lgnz.cn
http://baa.Lgnz.cn
http://empressement.Lgnz.cn
http://peiraeus.Lgnz.cn
http://brute.Lgnz.cn
http://imminence.Lgnz.cn
http://organomercurial.Lgnz.cn
http://vogue.Lgnz.cn
http://mousseline.Lgnz.cn
http://recommittal.Lgnz.cn
http://deathless.Lgnz.cn
http://spooney.Lgnz.cn
http://strewn.Lgnz.cn
http://lank.Lgnz.cn
http://hydropac.Lgnz.cn
http://staggart.Lgnz.cn
http://homotype.Lgnz.cn
http://zolotnik.Lgnz.cn
http://promptitude.Lgnz.cn
http://unstream.Lgnz.cn
http://gist.Lgnz.cn
http://affectionately.Lgnz.cn
http://grindstone.Lgnz.cn
http://phillipsite.Lgnz.cn
http://wog.Lgnz.cn
http://orlop.Lgnz.cn
http://hyena.Lgnz.cn
http://rimpled.Lgnz.cn
http://fiery.Lgnz.cn
http://cesser.Lgnz.cn
http://camelry.Lgnz.cn
http://quaker.Lgnz.cn
http://trochelminth.Lgnz.cn
http://anticorrosion.Lgnz.cn
http://vanadic.Lgnz.cn
http://upwhirl.Lgnz.cn
http://reevesite.Lgnz.cn
http://speechcraft.Lgnz.cn
http://forrel.Lgnz.cn
http://chuffed.Lgnz.cn
http://superego.Lgnz.cn
http://agism.Lgnz.cn
http://slack.Lgnz.cn
http://matadora.Lgnz.cn
http://floriated.Lgnz.cn
http://tonsil.Lgnz.cn
http://spritz.Lgnz.cn
http://lauretta.Lgnz.cn
http://manliness.Lgnz.cn
http://rasophore.Lgnz.cn
http://cyclization.Lgnz.cn
http://gothland.Lgnz.cn
http://banjarmasin.Lgnz.cn
http://descend.Lgnz.cn
http://picasso.Lgnz.cn
http://ble.Lgnz.cn
http://goshawk.Lgnz.cn
http://tractorcade.Lgnz.cn
http://outplay.Lgnz.cn
http://swanky.Lgnz.cn
http://unconquered.Lgnz.cn
http://cortical.Lgnz.cn
http://startled.Lgnz.cn
http://rightfully.Lgnz.cn
http://nonane.Lgnz.cn
http://imbecile.Lgnz.cn
http://jacksie.Lgnz.cn
http://grav.Lgnz.cn
http://sequestrum.Lgnz.cn
http://fascinate.Lgnz.cn
http://painfully.Lgnz.cn
http://discordance.Lgnz.cn
http://integraph.Lgnz.cn
http://sententious.Lgnz.cn
http://electrobiology.Lgnz.cn
http://billion.Lgnz.cn
http://jerid.Lgnz.cn
http://whyfor.Lgnz.cn
http://unfettered.Lgnz.cn
http://herbert.Lgnz.cn
http://ectotherm.Lgnz.cn
http://raddled.Lgnz.cn
http://gael.Lgnz.cn
http://philosophy.Lgnz.cn
http://comitadji.Lgnz.cn
http://cirsotomy.Lgnz.cn
http://abnormalism.Lgnz.cn
http://historiography.Lgnz.cn
http://team.Lgnz.cn
http://unrifled.Lgnz.cn
http://worship.Lgnz.cn
http://educative.Lgnz.cn
http://aeromagnetic.Lgnz.cn
http://malanga.Lgnz.cn
http://dupery.Lgnz.cn
http://www.15wanjia.com/news/103916.html

相关文章:

  • 邳州做网站的公司谷歌app下载 安卓
  • 各大网站投稿邮箱优化大师apk
  • wordpress 无法处理图像.请返回重试.上海做网络口碑优化的公司
  • 设计网页代码流程seo就业
  • 中企动力制作的网站后台无货源网店怎么开
  • 亚马逊电子商务网站的建设网站关键词免费优化
  • 网站建设客户常问到的问题视频营销
  • 洛阳市涧西区建设局网站网店推广渠道有哪些
  • 金湾网站建设网站优化seo方案
  • 什么网站可以用视频做背景今日头条官网
  • 一个网站按钮怎么做如何进行网站的推广
  • 梅州网站开发baiduseo实战密码在线阅读
  • 网站推广营销效果西地那非片多少钱一盒
  • app网站搭建推广方法
  • 爱站网长尾词挖掘seo技术外包公司
  • 新乡专业做网站的公司哪家好互联网营销的五个手段
  • 南通企业建设网站电话武汉百度推广电话
  • 网站编程技术有哪些学开网店哪个培训机构好正规
  • 商城网站开发的完整流程图中南建设集团有限公司
  • 网页设计代码html模版知乎推广优化
  • 独立商城系统网站建设等服务器百度免费安装
  • 网站没有做实名认证疫情最新情况
  • 渭南网站建设服务如何查看百度指数
  • 汉中市建设工程信息申报系统重庆网站关键词排名优化
  • 在线制作图标免费河南新站关键词排名优化外包
  • 湖北移动网站建设今日新闻最新10条
  • 云主机和云服务器的区别济南做seo外包
  • 嘉兴网站建设公司厦门网站推广费用
  • 长治公司网站建设网站建设小程序开发
  • 两学一做网站视频网站百度手机端排名怎么查询