Coder Social home page Coder Social logo

proglangbase / bbhw Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 4.0 307 KB

Bye Bye Hello World

License: Mozilla Public License 2.0

C 2.52% Shell 32.86% PHP 1.86% Batchfile 1.02% APL 7.37% Scheme 13.78% Racket 1.66% Haskell 2.32% F# 1.42% J 6.92% Erlang 6.99% BQN 11.84% Elixir 4.47% Common Lisp 1.16% Chapel 1.47% Forth 2.36%

bbhw's Introduction

Bye Bye Hello World

Traditionally, the Hello World program is the first example offered as the introduction to a programming language and does nothing more than output the string "Hello World" to the output medium--generally the console. While adequate to demonstrate a particular language can actually do something, for anyone other than the novice programmer, a more thorough example is called for.

These code examples attempt to demonstrate basic capabilities of the languages we will examine by expanding Hello World to include:

  • Command Line Parameters
    Taking input criteria from the command line.

  • Prompted Input
    Prompting the user for input criteria.

  • Input Validation
    Examination of input criteria against programmed limits.

  • Conditional Branching
    Altering the execute path based on conditions.

  • Iteration
    Repeated execution until a condition is met.

Usage

bbhw [count]

where: count = Number of iterations. User prompted of not supplied.

Result

Counts down from count to 0, pausing between each iteration, and prints each count until complete.

bbhw's People

Contributors

c4augustus avatar sthames42 avatar samirose avatar lonetech avatar abrudz avatar

Stargazers

Noah avatar Sergio Soares avatar  avatar Andy Kluger avatar compwron avatar  avatar

Watchers

 avatar  avatar

bbhw's Issues

Haskell bye bye hello world

Neat idea. Here's an example of abusing Haskell to write this program; being so IO centric, it only leaves the IO monad in a few spots, and I wrote most of it with do blocks.

#! /usr/bin/env runghc
-- Ignoring the shebang line above is a GHC extension 
-- (see 6.19.6. Whitespace)

-- LANGUAGE here is a pragma, not a comment!
{-# LANGUAGE Haskell2010, NumericUnderscores #-}
-- The NumericUnderscores extension is enabled by default in
-- GHC2021 or GHC2024, it got switched off by Haskell2010. 

-- GHC specific delay. 
-- There is no standard delay, and the POSIX ones may be interrupted.
import Control.Concurrent (threadDelay)

import Control.Monad (forM_)
import Numeric (readDec)
import System.Environment (getArgs)
import System.IO (stdout, hSetBuffering, BufferMode(NoBuffering))

-- Sequential do style; this program is heavily IO centric.
main = do
  let   -- could move these functions out of main
    ensureCount s = case readDec s of
      [(n,"")] -> return n
      _ -> do
        putStrLn ("Invalid countdown "++s++", try again...")
        demandCount
    demandCount = do
      putStr "Count? "
      s <- getLine
      ensureCount s
  args <- getArgs
  hSetBuffering stdout NoBuffering
  count <- case args of
    [arg] -> ensureCount arg
    _     -> demandCount
  putStr "World, Hello..."
  forM_ [count, count-1 .. 1] $ \i -> do
    putStr (show i ++ "...")
    threadDelay 1_000_000  -- Here are our two extensions.
  putStrLn "Bye Bye."

Contributing guidelines?

Hello!

I'd like to contribute a new language example, but I have some questions about contribution expectations:

  • is it required to include the same Mozilla public license I'm seeing in the other examples?
  • if the example can either be compiled or run more like a script, should both be reflected in the run file, or just the compilation route there while leaving a nice shebang on the source file, or what?
  • if the compiler is not commonly packaged, should the run script download it, or instead download its source and compile the compiler itself?
  • any other notes new contributors should be aware of before submitting a PR?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.