Create a file on magnetic tape: Difference between revisions

From Rosetta Code
Content added Content deleted
(added Scala)
m (removed REXX from omit list. -- ~~~~)
Line 95: Line 95:
{{omit from|PARI/GP}}
{{omit from|PARI/GP}}
{{omit from|Retro}}
{{omit from|Retro}}
{{omit from|REXX|not OO}}
{{omit from|TI-89 BASIC}}
{{omit from|TI-89 BASIC}}

Revision as of 22:36, 23 November 2013

Task
Create a file on magnetic tape
You are encouraged to solve this task according to the task description, using any language you may know.

The task is to create a new file called "TAPE.FILE" of any size on Magnetic Tape

JCL

<lang JCL>// EXEC PGM=IEBGENER //* Create a file named "TAPE.FILE" on magnetic tape; "UNIT=TAPE" //* may vary depending on site-specific esoteric name assignment //SYSPRINT DD SYSOUT=* //SYSIN DD DUMMY //SYSUT2 DD UNIT=TAPE,DSN=TAPE.FILE,DISP=(,CATLG) //SYSUT1 DD * DATA TO BE WRITTEN TO TAPE /* </lang>

Perl 6

<lang perl6>my $tape = open "/dev/tape", :w or die "Can't open tape: $!"; $tape.say: "I am a tape file now, or hope to be soon."; $tape.close;</lang>

PicoLisp

<lang PicoLisp>(out "/dev/tape"

  (prin "Hello World!") )</lang>

Python

<lang python>>>> with open('/dev/tape', 'w') as t: t.write('Hi Tape!\n') ... >>> </lang>

Racket

<lang Racket>

  1. lang racket

(with-output-to-file "/dev/tape" #:exists 'append

 (λ() (displayln "I am a cheap imitation of the Perl code for a boring problem")))

</lang>

Scala

Unix

Assuming device is attached to "tape" <lang Scala>object LinePrinter extends App {

 import java.io.{ FileWriter, IOException }
 {
   val lp0 = new FileWriter("/dev/tape")
   lp0.write("Hello, world!")
   lp0.close()
 }

}</lang>

Tcl

Tcl does not have built-in special support for tape devices, so it relies on the OS to handle most of the details for it. Assuming a relatively modern Unix:

Translation of: UNIX Shell

<lang tcl>cd /tmp

  1. Create the file

set f [open hello.jnk w] puts $f "Hello World!" close $f

  1. Archive to tape

set fin [open "|tar cf - hello.jnk" rb] set fout [open /dev/tape wb] fcopy $fin $fout close $fin close $fout</lang>

TUSCRIPT

<lang tuscript>$$ MODE TUSCRIPT STATUS = CREATE ("tape.file",tape-o,-std-) PRINT STATUS</lang> Output:

OK

UNIX Shell

<lang bash>#!/bin/sh cd # Make our home directory current echo "Hello World!" > hello.jnk # Create a junk file

  1. tape rewind # Uncomment this to rewind the tape

tar c hello.jnk # Traditonal archivers use magnetic tape by default

  1. tar c hello.jnk > /dev/tape # With newer archivers redirection is needed</lang>

ZX Spectrum Basic

The ZX Spectrum does not have file type extensions, so we save as TAPEFILE, rather than TAPE.FILE. We can use any start address, depending on where we want the data to come from. Here we dump the contents of the screen: <lang zxbasic>SAVE "TAPEFILE" CODE 16384,6912</lang>