Basics of Factor

Descrition del contenete del págine

Conversion de old BASIC-programas a Factor por aprender lu elementari de ti-ci lingue.

Etiquettes:

Diamond

! Diamond

! Original version in BASIC:
!     Example included in Vintage BASIC 1.0.3.
!     http://www.vintage-basic.net

! This version in Factor:
!     Copyright (c) 2024, Marcos Cruz (programandala.net)
!     SPDX-License-Identifier: Fair

! Written on 2024-11-30, 2024-12-03.

! Last modified 20241203T0106+0100.

USING: io math ranges sequences ;

IN: diamond

CONSTANT: lines 17

: print-star ( -- )
    "*" write ;

: print-space ( -- )
    " " write ;

: end-line ( -- )
    "" print ;

:: print-top ( height -- )
    lines 1 + 2 / height - 1 + [ print-space ] times
    height 2 * 1 -             [ print-star  ] times end-line ;
    ! Print the diamond top part, with the given _height_.

:: print-bottom ( height -- )
    height 1 +                     [ print-space ] times
    lines 1 + 2 / height - 2 * 1 - [ print-star  ] times end-line ;
    ! Print the diamond bottom part, with the given _height_.

: run ( -- )
    lines 2 / 1 + [1..b] [ print-top    ] each
    lines 2 /     [1..b] [ print-bottom ] each ;

MAIN: run

Name

! Name

! Original version in BASIC:
!     Example included in Vintage BASIC 1.0.3.
!     http://www.vintage-basic.net

! This version in Factor:
!     Copyright (c) 2024, Marcos Cruz (programandala.net)
!     SPDX-License-Identifier: Fair

! Written in 2024-11-30/12-02.

! Last modified 20241203T0108+0100.

USING: io kernel math math.parser sequences ;

IN: name

! XXX FIXME Prompts are printed only after both inputs! But
! it works fine on the graphical interface. Bug of Factor? 

: repetitions ( -- number )
    "" [ string>number dup ] [ drop "Enter a number: " write readln ] until ;
    ! Ask the user to enter a number. If the entry cannot be converted to a number, ask again.

: name ( -- string )
    "" [ dup "" = ] [ drop "What is your name? " write readln ] while ;
    ! Ask the user to enter a name. If the entry is empty, ask again.

: salute ( -- string )
    "Hello, " name append "!" append ;

: run ( -- )
    salute repetitions swap '[ _ print ] times ;

MAIN: run

Págines relatet

Basics off
Metaprojecte pri li projectes «Basics of…».
Basics of 8th
Conversion de old BASIC-programas a 8th por aprender lu elementari de ti-ci lingue.
Basics of Ada
Conversion de old BASIC-programas a Ada por aprender lu elementari de ti-ci lingue.
Basics of Arturo
Conversion de old BASIC-programas a Arturo por aprender lu elementari de ti-ci lingue.
Basics of C#
Conversion de old BASIC-programas a C# por aprender lu elementari de ti-ci lingue.
Basics of C3
Conversion de old BASIC-programas a C3 por aprender lu elementari de ti-ci lingue.
Basics of Chapel
Conversion de old BASIC-programas a Chapel por aprender lu elementari de ti-ci lingue.
Basics of Clojure
Conversion de old BASIC-programas a Clojure por aprender lu elementari de ti-ci lingue.
Basics of Crystal
Conversion de old BASIC-programas a Crystal por aprender lu elementari de ti-ci lingue.
Basics of D
Conversion de old BASIC-programas a D por aprender lu elementari de ti-ci lingue.
Basics of Elixir
Conversion de old BASIC-programas a Elixir por aprender lu elementari de ti-ci lingue.
Basics of F#
Conversion de old BASIC-programas a F# por aprender lu elementari de ti-ci lingue.
Basics of FreeBASIC
Conversion de old BASIC-programas a FreeBASIC por aprender lu elementari de ti-ci lingue.
Basics of Gleam
Conversion de old BASIC-programas a Gleam por aprender lu elementari de ti-ci lingue.
Basics of Go
Conversion de old BASIC-programas a Go por aprender lu elementari de ti-ci lingue.
Basics of Hare
Conversion de old BASIC-programas a Hare por aprender lu elementari de ti-ci lingue.
Basics of Haxe
Conversion de old BASIC-programas a Haxe por aprender lu elementari de ti-ci lingue.
Basics of Icon
Conversion de old BASIC-programas a Icon por aprender lu elementari de ti-ci lingue.
Basics of Io
Conversion de old BASIC-programas a Io por aprender lu elementari de ti-ci lingue.
Basics of Janet
Conversion de old BASIC-programas a Janet por aprender lu elementari de ti-ci lingue.
Basics of Julia
Conversion de old BASIC-programas a Julia por aprender lu elementari de ti-ci lingue.
Basics of Kotlin
Conversion de old BASIC-programas a Kotlin por aprender lu elementari de ti-ci lingue.
Basics of Lobster
Conversion de old BASIC-programas a Lobster por aprender lu elementari de ti-ci lingue.
Basics of Lua
Conversion de old BASIC-programas a Lua por aprender lu elementari de ti-ci lingue.
Basics of Nature
Conversion de old BASIC-programas a Nature por aprender lu elementari de ti-ci lingue.
Basics of Neat
Conversion de old BASIC-programas a Neat por aprender lu elementari de ti-ci lingue.
Basics of Neko
Conversion de old BASIC-programas a Neko por aprender lu elementari de ti-ci lingue.
Basics of Nelua
Conversion de old BASIC-programas a Nelua por aprender lu elementari de ti-ci lingue.
Basics of Nim
Conversion de old BASIC-programas a Nim por aprender lu elementari de ti-ci lingue.
Basics of Nit
Conversion de old BASIC-programas a Nit por aprender lu elementari de ti-ci lingue.
Basics of Oberon-07
Conversion de old BASIC-programas a Oberon-07 por aprender lu elementari de ti-ci lingue.
Basics of OCaml
Conversion de old BASIC-programas a OCaml por aprender lu elementari de ti-ci lingue.
Basics of Odin
Conversion de old BASIC-programas a Odin por aprender lu elementari de ti-ci lingue.
Basics of Pike
Conversion de old BASIC-programas a Pike por aprender lu elementari de ti-ci lingue.
Basics of Pony
Conversion de old BASIC-programas a Pony por aprender lu elementari de ti-ci lingue.
Basics of Python
Conversion de old BASIC-programas a Python por aprender lu elementari de ti-ci lingue.
Basics of Racket
Conversion de old BASIC-programas a Racket por aprender lu elementari de ti-ci lingue.
Basics of Raku
Conversion de old BASIC-programas a Raku por aprender lu elementari de ti-ci lingue.
Basics of Retro
Conversion de old BASIC-programas a Retro por aprender lu elementari de ti-ci lingue.
Basics of Rexx
Conversion de old BASIC-programas a Rexx por aprender lu elementari de ti-ci lingue.
Basics of Ring
Conversion de old BASIC-programas a Ring por aprender lu elementari de ti-ci lingue.
Basics of Rust
Conversion de old BASIC-programas a Rust por aprender lu elementari de ti-ci lingue.
Basics of Scala
Conversion de old BASIC-programas a Scala por aprender lu elementari de ti-ci lingue.
Basics of Scheme
Conversion de old BASIC-programas a Scheme por aprender lu elementari de ti-ci lingue.
Basics of Styx
Conversion de old BASIC-programas a Styx por aprender lu elementari de ti-ci lingue.
Basics of Swift
Conversion de old BASIC-programas a Swift por aprender lu elementari de ti-ci lingue.
Basics of V
Conversion de old BASIC-programas a V por aprender lu elementari de ti-ci lingue.
Basics of Vala
Conversion de old BASIC-programas a Vala por aprender lu elementari de ti-ci lingue.
Basics of Zig
Conversion de old BASIC-programas a Zig por aprender lu elementari de ti-ci lingue.

Extern ligamentes relatet