TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Getting Started with Ada by Way of Rust

3 点作者 MarcusE1W超过 1 年前

2 条评论

kevlar700超过 1 年前
Is this input validation an exceptional error or code flow?<p>Ada has &#x27;Valid and so you can also do e.g.<p>If Guess&#x27;Valid then ...<p>In order to check that the data is valid for the types range whilst avoiding the exception that would occur if otherwise read whilst containing invalid data.<p>Gnat also has the non standard &#x27;Valid_Scalars for records.<p>Which will check every scalar type in a record. This record may have been filled by unchecked_conversion which ironically does check the size at compile time. It is all very neat along with record overlays. I can&#x27;t stress enough how far ahead of the competition Ada is for handling hardware registers whether memory mapped or received.<p>Where is the link for pattern matching as I am unsure of the necessity of it in Ada? I prefer Adas features to Darts new pattern matching atleast for json validation. I do not otherwise have extensive experience of Darts pattern matching though or any of Rusts.
ajdude超过 1 年前
&gt; I&#x27;m sidestepping the issue of Ada string handling, which can get complicated: you have fixed-size, bounded, and unbounded strings. Usually you have to read in exactly the amount of characters in the fixed string (in this case three), but with this particular version of Get_Line you can read anything up to the maximum length, while the rest is left alone. That is why I initialize Guess to three blank spaces. Once we start actually reading numbers this will become a non-issue (or a different issue).<p>One easy way around this (and is often used when parsing a file line-by-line) is to take advantage of Ada&#x27;s scoping of new variables.<p>For example:<p><pre><code> loop Put_Line (&quot;Please enter a line.&quot;); declare New_Data : constant String := Get_Line; begin Put_Line (&quot;You said &quot; &amp; New_Data); exit when New_Data = &quot;quit&quot;; end; end loop; </code></pre> This insures that you are only using variables to the specific scope that you need (and I tend to declare that has constant unless you plan on modifying them).<p>Also, for anyone interested in getting into Ada, something I mentioned in a previous comment: yes easier than ever to get into Ada these days. There&#x27;s a bunch of tutorials on Adacore&#x27;s website [1] with a playground&#x2F;sandbox that you can mess with. With Alire[2] (which is to Ada what Cargo is to Rust), you can get the toolchain and any packages with a simple command. If you&#x27;re on linux or mac, you can also use GetAda[3] that will automatically install Alire for you.<p>[1] <a href="https:&#x2F;&#x2F;learn.adacore.com&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;learn.adacore.com&#x2F;</a><p>[2] <a href="https:&#x2F;&#x2F;alire.ada.dev&#x2F;docs&#x2F;#first-steps" rel="nofollow noreferrer">https:&#x2F;&#x2F;alire.ada.dev&#x2F;docs&#x2F;#first-steps</a><p>[3] <a href="https:&#x2F;&#x2F;github.com&#x2F;AJ-Ianozi&#x2F;getada&#x2F;tree&#x2F;main">https:&#x2F;&#x2F;github.com&#x2F;AJ-Ianozi&#x2F;getada&#x2F;tree&#x2F;main</a>
评论 #37467720 未加载