User Tools

Site Tools


first-program

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
first-program [2017/06/23 09:47]
barryfp
first-program [2018/08/16 10:05]
barryfp
Line 1: Line 1:
 In this section we'll walk through creating a simple command-line program in Dana. The program will use standard output, command-line input, and the file system. For recommended text editors in which to write Dana programs, see [[editors|this guide]]. In this section we'll walk through creating a simple command-line program in Dana. The program will use standard output, command-line input, and the file system. For recommended text editors in which to write Dana programs, see [[editors|this guide]].
  
-We begin by creating a new file ''​MyProgram.dn''​ and opening it in a text editor. In this file we declare the component that this source file will describe, declaring the interfaces that the component provides and requires. All behaviour in Dana is described using interfaces.+We begin by creating a new file ''​MyProgram.dn''​ and opening it in a text editor. In this file we declare the component that this source file will describe, declaring the interfaces that the component ​**provides** and **requires**. All behaviour in Dana is described using interfaces.
  
 <code d> <code d>
Line 9: Line 9:
 </​code>​ </​code>​
  
-Provided interfaces define the functionality that this component implements (or offers to other components). Required interfaces define the functionality that this component depends upon from other components. Every component must have at least one provided interface to make its functionality accessible. Components may then have zero or more required interfaces. As we'll see shortly, unlike in some other programming languages, Dana's interfaces are //​instantiable//​.+**Provided** interfaces define the functionality that this component implements (or offers to other components). ​**Required** interfaces define the functionality that this component depends upon from other components. Every component must have at least one provided interface to make its functionality accessible. As we'll see shortly, unlike in some other programming languages, Dana's interfaces are //​instantiable//​.
  
 The ''​App''​ interface has one function called ''​main''​. You can see the definition of this function in the file ''​App.dn''​ within the "​resources"​ folder of Dana's home directory. The ''​App''​ interface has one function called ''​main''​. You can see the definition of this function in the file ''​App.dn''​ within the "​resources"​ folder of Dana's home directory.
  
-A  provided interface function is implemented by writing a function of the same name but with the interface'​s type name, followed by a colon, preceding that function name. Now update our new component to look like this:+A  provided interface function is implemented by writing a function of the same name but with the interface'​s type name, followed by a colon, preceding that function name. We'll write a simple implementation of the App:main function, which looks like this:
  
 <code d> <code d>
Line 50: Line 50:
  
 And press enter. You should be prompted for some input and the program should ​ then create a text file in this directory containing whatever you choose as input. And press enter. You should be prompted for some input and the program should ​ then create a text file in this directory containing whatever you choose as input.
 +
 +The full list of interfaces that you can use in **requires** directives can be viewed at the [[http://​www.projectdana.com/​dana/​api/​|Dana API]] pages along with documentation of each one.
first-program.txt ยท Last modified: 2018/08/16 10:05 by barryfp